memory-cache

A simple in-memory cache. put(), get() and del()

node-cache

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');
console.log(cache.get('foo'))
 
// that wasn't too interesting, here's the good part 
 
cache.put('houdini', 'disapear', 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

bar
Houdini will now disapear
Houdini is null
  • 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)
  • Retreives a value for a given key
  • Deletes a key, return a bool specify whether or not a key was deleted.
  • Deletes all keys
  • Returns the current number of entries in the cache
  • Returns the number of entries taking up space in the cache
  • Will usually == size() unless a setTimeout removal went wrong
  • Turns on or off debugging
  • Returns the number of cache hits
  • Returns the number of cache misses.
  • Returns all the cache keys
  • Fork the project.
  • Make your feature addition or bug fix.
  • Send me a pull request.