stratocacher

0.1.5 • Public • Published

Stratocacher

A cache with pluggable layers.

Key features

Pluggable layers

Want to cache in memcached with a small in-memory LRU cache for hot values?

No problem! Stratocacher supports pluggable layers, and creating new layers is easy!

Automatic key generation

Stratocacher works on any function that:

  • Is named (e.g. function foo())
  • Takes only string and number arguments
  • Returns a JSON-serializable value or a promise of a JSON-serializable value.

Background rebuild

Stratocacher supports separate time-to-live and time-to-rebuild.

If a request comes in between ttr and ttl then a background rebuild will kick off and update the cache. No miss!

Usage

 
import * as stratocacher from "stratocacher"
import LayerObject from "stratocacher-layer-object"
 
const getFoo = stratocacher.wrap({
    ttl: stratocacher.constants.ONE_HOUR,
    layers: [
        LayerObject,
    ],
}, function getFoo(a, b, c) {
    return promiseOfSomethingExpensive(a, b, c);
});

wrap options

The wrap function accepts a number of options.

stratocacher.wrap(options, namedFunction);

ttl

Time to live for cache values.

ttr

Time to rebuild for cache values.

layers

An array of layer classes. Layers are checked in order, earlier layers first.

Package Sidebar

Install

npm i stratocacher

Weekly Downloads

17

Version

0.1.5

License

Apache-2.0

Unpacked Size

46.3 kB

Total Files

18

Last publish

Collaborators

  • gigabo