LRUCache
LRU Cache for node.js/browser.!NPM versionnpm-imagenpm-url !Build Statustravis-imagetravis-url !Downloadsdownloads-imagedownloads-url
使用链表实现的 LRU 缓存。
get
、set
和 update
方法会更新 LRU 优先级。Install
Node.js:npm install lrucache
bower:
bower install lrucache
Browser:
<script src="/pathTo/lrucache.js"></script>
API
const LRUCache = require('lrucache')
Class LRUCache(capacity)
capacity
: : Optional, Type:Number
, Default:Number.MAX_SAFE_INTEGER
.
const cache = LRUCache(100)
LRUCache.prototype.get(key)
Returnvalue
.let a = cache.get('a')
LRUCache.prototype.set(key, value)
Returnthis
.cache.set('a', [1, 2, 3])
LRUCache.prototype.update(key, fn)
Returnthis
, It only run when key exists.cache.update('a', function (a) {
a.push(4)
return a
})
LRUCache.prototype.remove(key)
Returnthis
.cache.remove('a')
LRUCache.prototype.removeAll(key)
Returnthis
.cache.removeAll()
LRUCache.prototype.keys()
Return a array ofkeys
.cache.keys()
LRUCache.prototype.has(key)
Returntrue
or false
.cache.has('a')
LRUCache.prototype.staleKey()
Return the stalestkey
or null
.let staleKey = cache.staleKey()
LRUCache.prototype.popStale()
Return the stalestdata
or null
.let staleDate = cache.popStale()
LRUCache.prototype.info()
Returninfo
.cache.info()