punycache
v1.0.0
Published
A minimalist cache
Downloads
31
Readme
punycache 🦴
A minimalist cache implementation.
Usage
const cache = require('punycache')()
cache.set('key', 'Hello World !')
console.log(cache.get('key')) // Hello World !
console.log(cache.keys()) // [ 'key' ]
console.del('key')
console.log(cache.get('key')) // undefined
Options
const cache = require('punycache')({
ttl: 200,
max: 100,
policy: 'lfu'
})
ttl
: (default:Number.POSITIVE_INFINITY
) Time to live in the cache, expressed in millisecondsmax
: (default:Number.POSITIVE_INFINITY
) Maximum number of keys to be stored in the cache (seepolicy
for cache replacement policies)policy
: Cache replacement policy, supported values are'lru'
(default) Least Recently Used (eachget
/set
updates used timestamp)'lfu'
Least Frequently Used (eachget
/set
increments usage frequency)
Implementation notes :
- keys are expected to be strings but no validation is done
- Values are stored and returned as-is
- Keys are removed from the cache ad-hoc (no timeout is being used)