LRU Cache for node.js/browser.
使用链表实现的 LRU 缓存。get、set 和 update 方法会更新 LRU 优先级。
Node.js:
npm install lrucache
bower:
bower install lrucache
Browser:
<script src="/pathTo/lrucache.js"></script>
const LRUCache = require('lrucache')
capacity: : Optional, Type: Number, Default: Number.MAX_SAFE_INTEGER.const cache = LRUCache(100)
Return value.
let a = cache.get('a')
Return this.
cache.set('a', [1, 2, 3])
Return this, It only run when key exists.
cache.update('a', function (a) {
a.push(4)
return a
})
Return this.
cache.remove('a')
Return this.
cache.removeAll()
Return a array of keys.
cache.keys()
Return true or false.
cache.has('a')
Return the stalest key or null.
let staleKey = cache.staleKey()
Return the stalest data or null.
let staleDate = cache.popStale()
Return info.
cache.info()