0.1.5 • Published 6 years ago

stratocacher v0.1.5

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
6 years ago

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.