1.0.0 • Published 9 years ago
@vanesyan/lru-cache v1.0.0
LRU cache
LRU cache
implementation on top of Map.
Installation
The easiest way to get the package is to install it through npm
$ npm install @vanesyan/lru-cacheExample
const cache = new LRUCache(100)
const obj = {}
cache.set('foo', 1)
cache.set(obj, 2)
console.log(cache.get(obj)) // => 2API
LRUCache(capacity, age)
capacity - Cache capacity
age - Maximum age of cached entry in milliseconds
cache#capacity
Returns the cache capacity.
cache#size
Returns the cache size.
cache#set(key, value)
Sets the value for the key in the cache.
cache.set('foo', { bar: 'baz' })cache#get(key)
Returns cached value associated to the key if exists otherwise returns
undefined.
cache.get('foo')cache#has(key)
Check whether an element with specified key exists or not.
Returns true if exists, otherwise false.
cache.has('foo')cache#clear()
Removes all cached key-value pairs.
cache.clear()cache#delete(key)
Removes the specified element by key from the cache.
Returns true if the key-value pair was successfully removed from cache,
otherwise false.
cache.delete('foo')Licence
Released under the MIT licence.
1.0.0
9 years ago