npm.io
0.3.0 • Published 6 years ago

kitten-cache

Licence
Apache-2.0
Version
0.3.0
Deps
0
Size
16 kB
Vulns
0
Weekly
0

Kitten-cache

Highly performant LRU cache.

Install

  1. Install
  npm i kitten-cache
  1. Require the dependence
  const Cache = require('kitten-cache');
  1. Declare new instance
  let cache = new Cache();

API

Instance
  new Cache(options)

  /*
    options : {
      size     : default 50,
      onRemove : function to call when a key/value is removed from the cache
    }
  */
Cache.set(key, value)
  let cache = new Cache();

  cache.set('a', 1);
Cache.get(key)
  let cache = new Cache();

  cache.set('a', 1);
  cache.get('a'); // -> 1
Cache.has(key)
  let cache = new Cache();

  cache.set('a', 1);
  cache.has('a'); // -> true
  cache.has('b'); // -> false
Cache.delete(key)
  let cache = new Cache();

  cache.set('a', 1);

  cache.delete('a'); // -> true
  cache.delete('b'); // -> false