I'm coming from Java world, and there are plenty implementations of (local) in-memory caches. Moreover in Java world there are SoftReference and WeakReference, and they're, by definition, ideal for cache implementation(s).
I know that JavaScript does not have anything similar, so I'm wondering is it possible to have some sort of cache functionality which will delete/release (all) cached objects if there are "low memory pressure". So far, I know for lru-cache module, but it's implementation holds objects up to some number/size, which is nice, but not good enough because, naturally, you'd expect from cache to release objects if there are not enough memory.
Is it even possible to get some event in NodeJS from system when process is running low on memory?
Or maybe some library that could raise an event, something like:
var cmmm = require('cool_memory_management_module');
cmmm.on('low_memory', function(){
//signaling to clear cache entries
});
So far, I've found npm memwatch, and npm usage modules, but still not able to combine all those pieces together.
There are no WeakReference
s or similar in JS yet, but shall come in ES6 (Version List).
So far, now you could build something that just checks every few seconds if the memory is running out and clean up your map.
setInterval(function() {
/* check if memory low and do something */
}, 2000).unref();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With