ptarjan/node-cache — pull request #12 by Aestek (2013-05-10 16:04:58+00:00)
Title: Add 'on the fly' cache adding support

Enable to effortlessly cache an item when it's not already present :

example :

memoryCache.get('myKey', function foudCallback(myData) {
// my data has been found or generated !
// use it
doSomething(myData);

}, function notFoundCallback(key, storeItCallback) {
// my data was not found
// generate it
var myData = 'I am data';
// trigger the callback,
// this will store the generated item in cache
// and pass it to 'foudCallback'

storeItCallback(myData, 60 * 60 * 24);
});