Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

219
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda