basic-cache
v0.0.4
Published
The most basic memory caching module ever.
Downloads
3
Readme
basic-cache
The best node caching module ever.
Getting Started
Install the module with: npm install basic-cache
var cache = require('basic-cache');
Methods
set(key, value, time)
Sets a key
to a value
and have it expire in time
milliseconds.
cache.set('company', 'MadGlory', 2000);
get(key)
Gets the value of key
.
var company = cache.get('company');
reset(key[, time])
Resets the expiration time of the key
. You can optionally set a new time
.
cache.reset('company'); // Resets to current time + original 2000
cache.reset('company', 1000); // Resets to current time + 1000
clear(key)
Removes the key
from the cache.
cache.clear('company');
clearAll()
Removes ALL the key
s from the cache.
cache.clearAll();
clean()
If for some reason a key
's time
expired, but it still exists in the cache running this method will clear all of those key
s.
cache.clean();
keys()
Returns all the names of the key
s in the cache as an array.
var keys = cache.keys();
size()
Returns the number of key
s that are currently in the cache.
var size = cache.size();
Namespacing
var cache = require('basic-cache');
cache.set('NAMESPACE1:company', 'MadGlory');
cache.set('NAMESPACE2:company', 'Company 2');
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
License
Copyright (c) 2013 MadGlory. Licensed under the MIT license.