bkjs-cache
v0.5.4
Published
Cache and LRU support for node.js and backendjs
Downloads
19
Readme
Cache module for node and backendjs
Usage
- Generic cache outside of V8 heap, implements named sets of caches,
name
refers to a separate named cache with its own set of keys:put(name, key, value)
- save a key value pair in the named cacheincr(name, key, value)
- increment a key value, non existent keys are assumed to be 0get(name, key)
- return value for a keydel(name, key)
- delete a keyexists(name, key)
- returns true if a key existskeys(name)
- return a list of all keys in the named cacheclear(name, ttl)
- delete all keys, if ttl is greater than 0 then it must be a number of seconds the cache will be alive till it expires, all subsequent items put in the cache will live until it expires automaticallynames()
- returs all existing named cachessize(name)
- returns size of a cacheeach(name, callback)
- call a callback for each keybegin(name)
- returns first keynext(name)
- returns next key or undefined when reached the end
- LRU internal cache outside of V8 heap:
lruInit(max)
- init LRU cache with max number of keys, this is in-memory cache which evicts older keyslruStats()
- return statistics about the LRU cachelruSize()
- return size of the current LRU cachelruCount()
- number of keys in the LRU cachelruPut(name, val [, expire])
- set/replace value by name, expire is the time in the future when this key becomes invalidlruGet(name [, now])
- return value by name, ifnow
is given in ms then a key with ttl below this timestamp will be considered invalid and deleted even if the expiration never been set beforelruIncr(name, val [, expire])
- increase value by given number, non existent items assumed to be 0lruDel(name)
- delete by namelruKeys([pattern] [,level])
- return all cache key names, if pattern is given match all keys beginning with it, if details is 1 then return an array with keys and expiration, if details is 2 then return an array with item key, value and expirationlruClear()
- clear LRU cachelruClean()
- remove the oldest item from the cachelruFront()
- return the oldest key
Author
Vlad Seryakov