simple.cache

a simple lru cache

ISC License

Downloads
199
Stars
1
Committers
1

simple.cache

a simple lru cache


api

const SimpleCache = require('simple.cache')

SimpleCache(max) max integer, default to 1000

methods

  • set(key, value) void, set a new entry and value
  • get(key) string or undefined, gets the entry's value from a given key
  • has(key) boolean, check if a given key already exists
  • remove(key) void, remove a given key from the first cache
  • size() integer, get the size of the cache
  • clear() void, clear cache
  • keys() array, returns the keys from the cache
  • dump() object, retrieves the entire cache

example

const SimpleCache = require('simple.cache')

const myCache = SimpleCache()

myCache.set('foo', 123)
myCache.set('bar', 456)

myCache.get('bar')// returns 456

myCache.remove('foo')

myCache.size()// should return 1

myCache.clear()// both caches are reset

props to Dominic Tarr for the amazing LRU algorithm

ISC License (ISC)