-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Code from readme gives diskCache.set is not a funciton... is this library still valid ?
// node cachemanager
var cacheManager = require('cache-manager');
// storage for the cachemanager
var fsStore = require('cache-manager-fs');
// initialize caching on disk
const diskCache = cacheManager.caching({
store: fsStore,
options: {
path: 'diskcache', //path for cached files
ttl: 60 * 60, //time to life in seconds
maxsize: 1000*1000*1000, // max size in bytes on disk
zip: true, //zip files to save diskspace (default: false)
preventfill:true
}
});
(async () => {
await diskCache.set('key', 'value');
console.log(await diskCache.get('key')); //"value"
console.log(await diskCache.ttl('key')); //3600 seconds
await diskCache.del('key');
console.log(await diskCache.get('key')); //undefined
console.log(await getUserCached(5)); //{id: 5, name: '...'}
console.log(await getUserCached(5)); //{id: 5, name: '...'}
await diskCache.reset();
function getUserCached(userId) {
return diskCache.wrap(userId /* cache key */, function () {
return getUser(userId);
});
}
async function getUser(userId) {
return {id: userId, name: '...'};
}
})();
Metadata
Metadata
Assignees
Labels
No labels