easy-cache

An easy way to handle in-memory key/value cache

npm install easy-cache
3 downloads in the last day
8 downloads in the last week
26 downloads in the last month

easy-cache

Build Status

A simple NodeJS module to handle in-memory key/value cache.

Install

npm install easy-cache

Basic usage

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

cache.set('foo', 'bar');
console.log(cache.get('foo')); // output: bar
console.log(cache.getSize()); // output: 1
cache.unset('foo'); // remove specific record

cache.set('temporary', 'value', 100); // duration in ms
console.log(cache.get('temporary')); // output: value

setTimeout(function() {
  try {
    console.log(cache.get('temporary')); // throws an exception
  } catch(err) {
    console.log(err.message); // Invalid key: temporary
  }
}, 150);

setTimeout(function() {
  if (!cache.exists('temporary')) {
    console.log('Key does not exist');
  }
  cache.clear(); // remove all records
}, 200);

Credits

Inspired by node-cache.

npm loves you