clean-cache

1.0.2 • Public • Published

Clean Cache

Build Status Coverage Status dependencies Status

NPM

Simple single-file, in-memory javascript cache fully tested and without any dependencies.

Initially part of statg.

Install

npm install clean-cache

Use

const { Cache } = require('clean-cache');
 
const myCache = new Cache(30000);       // ttl in ms, if omitted defaults to 60s
 
// adding items
myCache.add('1', { foo: 'bar' });       // adds object under key '1' for 30s
myCache.add('2', { foo: 'bar' }, 1000); // expires in 1s instead of 30s
myCache.add(null, { foo: 'bar' });      // throws error
myCache.add(undefined, { foo: 'bar' }); // throws error
 
// retrieving items
myCache.retrieve('1');                  // returns { foo: 'bar' }
myCache.retrieve('non-existent');       // returns null
myCache.retrieve(null);                 // throws error
myCache.retrieve(undefined);            // throws error
 
// other
myCache.count();                        // returns number of objects in cache
myCache.tidy();                         // removes all expired items from cache

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i clean-cache

Weekly Downloads

152

Version

1.0.2

License

MIT

Unpacked Size

6.85 kB

Total Files

4

Last publish

Collaborators

  • kuper-adrian