JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 22104
  • Score
    100M100P100Q132236F

LRU Cache for node.js/browser.

Package Exports

  • lrucache

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lrucache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

LRUCache

LRU Cache for node.js/browser.

NPM version Build Status

使用链表实现的 LRU 缓存。getsetupdate 方法会更新 LRU 优先级。

Install

Node.js:

npm install lrucache

bower:

bower install lrucache

Browser:

<script src="/pathTo/lrucache.js"></script>

API

var LRUCache = require('lrucache')

LRUCache([capacity])

LRUCache 构造函数。

  • capacity: Number,可选,设置 LRUCache 的容量,未设置则为无限容量。
var cache = LRUCache(100)

LRUCache.prototype.get(key)

return value

var a = cache.get('a')

LRUCache.prototype.set(key, value)

return this

cache.set('a', [1, 2, 3])

LRUCache.prototype.update(key, fn)

return this,如果缓存 a 不存在,则不会执行。

cache.update('a', function (a) {
  a.push(4)
  return a
})

LRUCache.prototype.remove(key)

return this

cache.remove('a')

LRUCache.prototype.removeAll(key)

return this

cache.removeAll()

LRUCache.prototype.keys()

return a array of keys

cache.keys()

LRUCache.prototype.has(key)

return true or false

cache.has('a')

LRUCache.prototype.staleKey()

return the stalest key or null

vat staleKey = cache.staleKey()

LRUCache.prototype.popStale()

return the stalest data or null

var staleDate = cache.popStale()

LRUCache.prototype.info()

return info

cache.info()