0.1.0 • Published 9 years ago

cache-wrapper v0.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
9 years ago

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
0.1.0

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2-n

9 years ago

0.0.1

9 years ago