cachepot

0.0.1 • Public • Published

cachepot · Build Status Codecov

Itsy-bitsy cache module. Smells as good as flowers.

Usage

Cachepot has almost the same external-facing API as the ES6 Map, but with some additional methods and configuration options.

const cache = new Cachepot()
cache.set('key', 'value')
cache.get('key')
cache.wrap('key', () => 'value')

new Cachepot(options)

Key Description Default
ttl Time in milliseconds until the key/value pair expires. 60 x 60

cache.wrap(key, callback)

This method will either return the value if it exists, or set a new one by calling the callback function. The return value of the function will be set as the new value for the key.

const cache = new Cachepot()
cache.wrap('key', () => {
  const value = createComplicatedObject()
  return value
})

cache.set(key, value, ttl)

This method has the same API as Map.set(), but with an additional optional ttl argument. This will override the configured TTL option.

Readme

Keywords

Package Sidebar

Install

npm i cachepot

Weekly Downloads

0

Version

0.0.1

License

ISC

Last publish

Collaborators

  • jasonetco