Cacher
A simple module for caching using Redis.
Introduction
Cacher is a wrapper module to abstract cache details and handling in order to make it easier for clients to simply get and set cached data.
Cacher has five public functions: init
, setCachePrefix
, getData
, setData
and setTTL
. The most common methods you'll use after init
will be the getData
and setData
methods.
init
Used to initialize a cacher object with an object containing the address, port and database number for use with Redis.
let cacher = ;cacher;
setCachePrefix
By default Cacher prefix keys in Redis with the word cacher
. To specify an alternative prefix use the setCachePrefix member.
cacher;
getData
/** * @name getData * @summary Retrieve data from cache using key. * @param * @return */
setData
/** * @name setData * @summary Place data in cache based on key for a duration of cacheDurationInSeconds. * @param * @param * @param * @return */
setTTL
/** * @name setTTL * @summary Set Time To Live for cache entry associated with key. * @param * @param * @return */
Tests
This module contains tests in the specs
folder.
To run them make sure you have mocha installed:
$ npm install mocha -g
Then run:
$ npm run test