Skip to content


Subversion checkout URL

You can clone with
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

87 lines (50 sloc) 1.601 kb


A simple in-memory cache for node.js


npm install memory-cache


var cache = require('memory-cache');

// now just use the cache

cache.put('foo', 'bar');

// that wasn't too interesting, here's the good part

cache.put('houdini', 'disappear', 100) // Time in ms
console.log('Houdini will now ' + cache.get('houdini'));

setTimeout(function() {
  console.log('Houdini is ' + cache.get('houdini'));
}, 200);

which should print

Houdini will now disappear
Houdini is null


put = function(key, value, time)

  • Simply stores a value.
  • If time isn't passed in, it is stored forever.
  • Will actually remove the value in the specified time (via setTimeout).
  • Returns the cached value.

get = function(key)

  • Retrieves a value for a given key

del = function(key)

  • Deletes a key, return a bool specifying whether or not the key was deleted

clear = function()

  • Deletes all keys

size = function()

  • Returns the current number of entries in the cache

memsize = function()

  • Returns the number of entries taking up space in the cache
  • Will usually == size() unless a setTimeout removal went wrong

debug = function(bool)

  • Turns on or off debugging

hits = function()

  • Returns the number of cache hits

misses = function()

  • Returns the number of cache misses

keys = function()

  • Returns all the cache keys

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Send me a pull request.
Jump to Line
Something went wrong with that request. Please try again.