Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!