0.3.0 • Published 4 years ago

kitten-cache v0.3.0

Weekly downloads
1,083
License
Apache-2.0
Repository
-
Last release
4 years ago

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