title: Caching with Node Cache doesnt persist data
body: <p>I am trying to build a cache using node-cache npm module, where I want to save the first 100 records of the API call in the cache, so I don't have to call the API again. The front end is build with React.</p>
  
  <p>The problem I have is that every time the browser refreshes, I lose the cache. My code looks like this: </p>
  
  <pre><code>getAll: () =&gt; {
      if (cache.keys().length) {
        console.log(' data persists', )
        const keysArr = cache.keys();
        return getAllCachedRecords(keysArr)
      }
      cache.mset([{key: 1, val: {a: 1, b: 2}}, {key: 2, val: {a: 1, b: 2}}, {key: 3, val: {a: 1, b: 2}}])
      console.log(cache.keys(), 'here i can see the saved data outside if statement')
      return fetchRequest(BASE_URL)
    }
  
  const fetchRequest = (url) =&gt; {
      return fetch(url)
        .then(res =&gt; res.status &lt;= 400 ? res : Promise.reject(res))
        .then(res =&gt; res.json())
        .then(res=&gt;{
          setAllCachedRecords(res);
          return res;
        })
        .catch((err) =&gt; {
          console.log(`${err.message} while fetching /${url}`)
        });
  };
  </code></pre>
  
  <p>Basically, I want my function getAll to first check if I have something in the cache(cache.keys returns the array of the existing keys), and if so, return this info. Otherwise, call the API, set the info in the cache, and return that info. </p>
  
  <p>However, the cache.keys().length is never true, even if I manually set a couple of keys outside the conditional statement, and check their existence afterwards. Am I flushing the data when I refresh the browser, and if so, what solutions do I have to not have to call the API every time?</p>