cache-wrapper

0.1.0 • Public • Published

Build Status Dependency Status npm version

Installation

npm install cache-wrapper

Usage

The example below shows how you can use cache-wrapper to iteratively wrap each function in a resource intensive/slow data store object, so that repeat calls to its methods with the same arguments will use a cached response from the first call.

var cacheWrapper = require('cache-wrapper');
var dataStore = {
    getThing: function (id) {
        // Do something resource intensive
    }
};

var proxiedDataStore = cacheWrapper.wrap(dataStore);
var thing = proxiedDataStore.getThing(1);

Alternatively, you may wrap individual functions for more fine-grained control.

var proxiedGetThing = cacheWrapper.wrap(dataStore.getThing);
var thing = proxiedGetThing(1);

Cache Expiration

A TTL can be set on caches to ensure that cached data doesn't go stale.

var proxiedDataStore = cacheWrapper.wrap(dataStore, { ttl: 5000 }); // Keep for 5000ms

Readme

Keywords

Package Sidebar

Install

npm i cache-wrapper

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • thody