title: Node.js Cache Memory Management
body: <p>I'm currently looking at <a href="https://www.npmjs.com/package/node-cache" rel="nofollow noreferrer">this</a> NPM package to cache data in Node.js. I have also thought about just having a JSON object that stores keys and more JSON objects as values and just using that as a cache.</p>
  
  <p>My question is this. In terms of memory management how would a solution like this work? Obviously Node.js doesn't have unlimited memory, and operating a cache is the lowest priority in terms of what should be freed up if more memory is required.</p>
  
  <p>How could I ensure that it's not caching every single piece of data and not eating up memory if other resources need it?</p>
  
  <p>I don't mind it caching an unlimited amount of data so long as when other resources need memory that it starts to release that memory and takes lower priority.</p>