0.5.3 • Published 6 years ago

lru-with-ttl v0.5.3

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

LRU with Ttl

A Time-aware LRU key-value store with global/per value ttl setting and efficient lookup

See: https://en.wikipedia.org/wiki/Cachereplacement_policies#Time_aware_least_recently_used(TLRU)

API

const LRU = require('lru-with-ttl')
const store = new LRU({ maxItems, ttl, touchOnGet })

store.set(k, v, [ttl])

store.get(k)

// Event handlers are of the form (key, value) => { ... }

store.on('create', onCreate)
store.on('update', onUpdate)
store.on('eviction', onEviction)

options

maxItems (default : 1000)

Max items to store before the oldest item gets evicted

ttl (default : undefined)

Cache expiry time in milliseconds. When undefined items purged only when maxItems is reached.

touchOnGet

By default items get touched when read. Setting this to true will cause the items to expire after ttl and keep their place in the LRU queue regardless of reads.

License

MIT

0.5.3

6 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago