Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
update cached data using node-cache

I'm using Nextjs and I cached some API using node-cache. if data doesn't exist in the cache, I request API and put them into cache in server else I get data from the cache. But this API may be updated every 1 month from the backend. I don't how to find out when these data are updated and when should call API and update the cache.

const NodeCache = require("node-cache");

const myCache = new NodeCache();

let navigation = myCache.get("navigation");
let footer = myCache.get("footer");
if (navigation !== undefined) {
        response = {
          navigation: navigation,
          footer: footer,
        };
      } else {
        await Promise.all([promise1]).then(
          (res) => {
            myCache.set("navigation", res[0].data['navigation-menu'], 3600);
            myCache.set("footer", res[0].data['footer-menu'], 3600);
             response = {
              navigation: res[0].data['navigation-menu'],
              footer: res[0].data['footer-menu'],
       };
          },
        );
      }

I expire cache every 1 hour but I think this is not the best solution

about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda