rrcache
Random Replacement Cache with TTL and preload option. A simple and clean RR cache that just works.
See Cache Types for a comparison of different cache algorithms
install
npm i rrcache
usage
var defaultOptions = max: 100000 // max entriesvar rrcache = defaultOptions
get(key) => value
value = rrcache
set(key, value[, ttl])
optional ttl (time to live)
setting a key without a ttl will clear any current timeout
rrcache // will automatically make room or rrcache // expire key in 60 seconds
clear()
clear the cache
rrcacheclear
options(newOptions)
change the cache options, currently only can change the max threshold. If the max
cache size is decreased, the cache will automatically clean the cache to the new size. max = 0
disables the RR cleaning of the cache.
rrcacheoptionsmax: 0 // disable cache
length()
return the number of entries in the cache
var currentEntries = rrcachelength
values()
return the current key/values of the cache
rrcacherrcache var values = rrcacheconsole "firstbase": "jon" "secondbase": "joe"
or persist the cache values for later
fs = fs
load(values)
manually load the cache with a set of values
fs = rrcache
loadFile()
rrcache
saveFile()
rrcache// or if previous loadFilerrcache
preload the cache with a set of values
fs = var initialData = JSONvar rrcache = data: initialData // preload cache
reload the cache during init
var rrcache = file: 'mycache.json' max: 1000000
multiple cache instances
var RRCache = var cache1 = var cache2 =