
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
memory-cache
Advanced tools
A simple in-memory cache for node.js
npm install memory-cache --save
var cache = require('memory-cache');
// now just use the cache
cache.put('foo', 'bar');
console.log(cache.get('foo'));
// that wasn't too interesting, here's the good part
cache.put('houdini', 'disappear', 100, function(key, value) {
console.log(key + ' did ' + value);
}); // Time in ms
console.log('Houdini will now ' + cache.get('houdini'));
setTimeout(function() {
console.log('Houdini is ' + cache.get('houdini'));
}, 200);
// create new cache instance
var newCache = new cache.Cache();
newCache.put('foo', 'newbaz');
setTimeout(function() {
console.log('foo in old cache is ' + cache.get('foo'));
console.log('foo in new cache is ' + newCache.get('foo'));
}, 200);
which should print
bar
Houdini will now disappear
houdini did disappear
Houdini is null
foo in old cache is baz
foo in new cache is newbaz
setTimeout)function(key, value) {})null== size() unless a setTimeout removal went wrongexport into the cacheimport will remain in the cacheskipDuplicates is trueoptions:
skipDuplicates: If true, any duplicate keys will be ignored when importing them. Defaults to false.require('cache') would return the default instance of Cacherequire('cache').Cache is the actual classnode-cache is another in-memory caching solution for Node.js. It offers similar functionality to memory-cache, including setting, getting, and deleting cache values, as well as setting expiration times. One key difference is that node-cache provides additional features such as event listeners for cache hits and misses, and the ability to store multiple values at once.
lru-cache is a caching solution that implements a Least Recently Used (LRU) algorithm. This means that it automatically removes the least recently accessed items when the cache reaches its maximum size. This can be useful for managing memory usage more effectively compared to memory-cache, which does not have built-in eviction policies.
cache-manager is a more advanced caching solution that supports multiple storage backends, including in-memory, Redis, and others. It provides a consistent API for interacting with different types of caches and offers features such as hierarchical caching and custom cache stores. This makes it more versatile than memory-cache, which is limited to in-memory storage.
FAQs
A simple in-memory cache. put(), get() and del()
The npm package memory-cache receives a total of 619,817 weekly downloads. As such, memory-cache popularity was classified as popular.
We found that memory-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.