ccache

0.1.0 • Public • Published

ccache

The methods all return promises (when.js).

Caveats

  • The store method will convert objects to JSON strings but fetch will not restore them
  • The purge method does not call the redis DEL command, instead it updates the expiration to be 1 second and lets redis clean it up

Usage

  var ccache = require('ccache');

  var cache = new ccache();

  // store a value, defaulting to a 6 hour expiration
  cache.store('key', 'value').then(function(result) {
    // result === true if stored successfully
    // result === false if store failed
  }, function(error) {
    // error checking
  });

  // store a value, defaulting to a custom expiration (in seconds)
  cache.store('key', 'value', 60).then([...])

  // fetch the stored value
  cache.fetch('key').then(function(result) {
    // see Caveats section
    //
    // result === value if key stored in cache
    // result === false if key not found
  }, function(error) {
    // error checking
  });

  // fetch the stored value and expire it
  //
  // internally the expire argument is set to false
  // unless you pass in true. So you can omit `false`
  // if you don't want to expire when fetching the
  // value
  cache.fetch('key', true).then([...])


  cache.purge('key').then(function(result) {
    // result === true if the key was purged
    // result === false if the key was not purged
  }, function(error) {
    // error checking
  });

Readme

Keywords

none

Package Sidebar

Install

npm i ccache

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • cabrel