node-memory-cache
A lightweight memory caching module for node.js:
- Key/Value store, except that for each key you can store multiple properties, like:
key.property1
orkey.property2
. - Native support for counters.
- You can set different expirations on properties, like:
key.property1
expires every 1000ms, andkey.property2
every 5000ms.
Installation
npm install node-memory-cache
Usage
var cache = ; // Set an object propertycache; // Set an object property with a 3000ms expirationcache; // Get the object propertiescache;cache; // Set a new property that is a counter, and increment it with +1cache; // Set a new property that is a counter, and increment it with +10, with a 5000ms expiration.cache; // Decrementing a value, it is like incrementing it with a negative amountcache; // Expiration dates can be overwritten by specifying them againcache;cache; // Now the expiration has been updated to 5000ms // The same for counterscache; // The counter has a 2000ms expiration // The counter still keeps a 2000ms expirationcache; cache; // We update the expiration date to 5000ms while incrementing the valuecache; // To remove an expiration just set it to zerocache; // We removed the expiration to this property // Delete a property/countercache; // Get all items storedvar data = cache; // Initialize the cache with some predefined data: expected to be in the same format as the return value of getAll()cache;
Support
Open an issue on GitHub.