LRUCache
LRU Cache for node.js/browser.
使用链表实现的 LRU 缓存。get
、set
和 update
方法会更新 LRU 优先级。
Install
Node.js:
npm install lrucache
bower:
bower install lrucache
Browser:
API
const LRUCache =
Class LRUCache([capacity])
capacity
: : Optional, Type:Number
, Default:Number.MAX_SAFE_INTEGER
.
const cache =
LRUCache.prototype.get(key)
Return value
.
let a = cache
LRUCache.prototype.set(key, value)
Return this
.
cache
LRUCache.prototype.update(key, fn)
Return this
, It only run when key exists.
cache
LRUCache.prototype.remove(key)
Return this
.
cache
LRUCache.prototype.removeAll(key)
Return this
.
cache
LRUCache.prototype.keys()
Return a array of keys
.
cache
LRUCache.prototype.has(key)
Return true
or false
.
cache
LRUCache.prototype.staleKey()
Return the stalest key
or null
.
let staleKey = cache
LRUCache.prototype.popStale()
Return the stalest data
or null
.
let staleDate = cache
LRUCache.prototype.info()
Return info
.
cache