Package Exports
- nodex-cache
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nodex-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
nodex-cache
A simple caching module for node js that has
set,getanddeletemethods. Keys can have a timeout (ttl) after which they expire and are deleted from the cache.
Installation
npm i --save nodex-cacheUsage
const node_cache = require('nodex-cache');
let { cache, expire } = node_cache;Simple Cache
const simpleCache = cache();
simpleCache.set('a', 1)
simpleCache.set('b', 3)
console.log(simpleCache.remove('b')) // 3
console.log(simpleCache.get('a')) // 1
console.log(simpleCache.remove('b')) // undefinedExpiring Cache
const expirationHandler = (key, value) => {
console.log(`expired ${key}: ${value}`) // expired b: 2
}
const expiringCache = expire(cache(), expirationHandler)
expiringCache.set('a', 1, 1000)
expiringCache.set('b', 2) //default expiry is 1000
expiringCache.set('c', 3) //default expiry is 1000
console.log(expiringCache.remove('b')) // 2
console.log(expiringCache.get('a')) // 1
setTimeout(() => {
console.log(expiringCache.get('a')) // undefined
}, 1200)License
MIT © Liju Kuriakose