How do I manage memory in node js

How do I manage memory in node js


I’m writing a node.js software module which stores a number of strings of varying length in an object map. This is essentially serving as a in memory cache for my overall software.

I was wondering how do I account for the fact that more memory will be used up the longer my application is running and I understand node processes by default have a memory limit imposed by the v8 engine.

I have already put in place code which after a certain time removes old cache entries but this does not protect against a lot of cache entries being placed in a short amount of time.

Problem courtesy of: user2220365


As dm03514 says, use a dedicated cache component. Memcached will do this for you, as will Redis.

The main problem you will face is invalidation, both of these allow you to set expiry times for keys.

Solution courtesy of: Joe


Leave a Reply

Your email address will not be published. Required fields are marked *