• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

121
Vistas
How can I cache the API response for 24hrs and after that period we can call the API and update the cache again in ReactJS

How can I cache the API response?

In the current scenario, We have issue like API getting hits by 10k times and this API we need to call once only after 24hrs.

let configurationsLoaded = false
async function fetch() {
  try {
     // Here we will have the JSON response
    const data = await agent.Core.fetch() 
    if (!Array.isArray(data)) {
      throw new Error('Invalid response (' + JSON.stringify(data) + ')')
    }

    data.forEach(({ Name, Value }) => {
      if (Name.startsWith('url.path.')) {
        config.urls[Name.replace('url.path.', '')] = Value
      } else if (Name.startsWith('kafka.topic.')) {
        config.kafkaTopics[Name.replace('kafka.topic.', '')] = Value
      }
    })

    configurationsLoaded = Object.keys(config.urls).length > 0
    if (configurationsLoaded) {
      configurationsLoadedTime = Date.now()
    }
  } catch (error) {
    configurationsLoaded = false
    showToastMessage('Failed to fetch app configurations: ' + error.message)
    return console.error('Failed to fetch app configurations', error)
  }
}

Do we need to use LocalStorage API's for caching a data? because I have read in many articles even after encryption of the data. It's not safe! Or Can we use Browser's Cache API? https://developer.mozilla.org/en-US/docs/Web/API/Cache

Also we have use 'superagent-bluebird-promise' npm package, So can we use interceptor to cache the call?

What will be the best approach we can use here to persist data for 24hrs and call it after every 24hrs of time.

P.S I'm not asking for the code, but if any one could give me a steps to transform into a result would be a great help! Thanks in advance!

almost 3 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda