basiccache.js
An extremely basic cache with a simple expiry system
Installation
npm install basiccache
Usage
first
node
var BasicCache = require('basiccache');
html
<script src="basiccache.min.js"></script>
then
var cache = new BasicCache();
cache.set('key', 'value', 5 * 1000);
cache.get('key');
setTimeout(function() {
cache.get('key');
}, 3 * 1000);
setTimeout(function() {
cache.get('key');
}, 6 * 1000);
expiry is set per individual key
Function
new BasicCache([opts])
opts.debug
: print debug info to the console on stderr, defaults to false
cache.get(key)
returns the cached item if it exists and hasn't expired. if the item doesn't
exist, or has been invalidated, this function will return undefined
cache.set(key, value, [expires])
set a key to a value, expires
is the number of milliseconds from now when
this specific cache entry expires, defaults to 5 minutes
cache.remove(key)
remove an entry from the cache, no errors are throw if they key doesn't exist
License
MIT