Git Product home page Git Product logo

cacheman-multi's Introduction

cacheman-multi

Multi-tiered cacheman cache

Installation

This module is installed via npm:

npm i cacheman-multi --save

Example Usage

var Cache = require('cacheman-multi')
var cache = new Cache(); // in-memory lru cache

// or namespaced cache
var cache = new Cache('todo'); // in memory default

// or with options
var cache = new Cache({ ttl: 90 });

// or namespaced with options
var cache = new Cache('todo', { ttl: 90 });

// or namespaced with a list of engines in the order they will be used
var cache = new Cache('todo', [
  { engine: 'memory', ttl: 60}, // in memory, 1 minute TTL
  { engine: 'redis',  ttl: 3600, port: 6379  /* default */, host: '127.0.0.1' /* default */}, // redis, 1 hour TTL
  { engine: 'mongo',  ttl: 3600, port: 27017 /* default */, host: '127.0.0.1' /* default */, username: 'usr', password: 'PaS$', database: 'my-cache-db', collection: 'my-collection', compression: false /* default */} // mongo 1 day TTL
]);

// or a quick memory and redis cache
var cache = new Cache(
  [ 'memory',
  { engine: 'redis', ttl: 600 }
]);

// or a quick memory and mongo cache
var cache = new Cache([
  'memory',
  { engine: 'mongo', url:'mongodb://127.0.0.1:27017/blog', collection: 'account', ttl: 600 }
]);

// or engines with different namespaces
var cache = new Cache([
  { engine: 'memory', namespace: 'foo' },
  { engine: 'file',   namespace: 'bar'}
]);

// set the value
cache.set('my key', { foo: 'bar' }, function (error) {
  if (error) throw error;

  // get the value
  cache.get('my key', function (error, value) {
    if (error) throw error;

    console.log(value); //-> {foo:"bar"}

    // delete entry
    cache.del('my key', function (error){
      if (error) throw error;

      console.log('value deleted');
    });
  });
});

Built on

And includes for convenience

Cacheman supported functions, so far

  • get
  • set
  • del
  • clear
  • use
  • wrap

CLI

Install

npm i cacheman-multi -g

Use

cacheman-multi --help

Rights

Copyright (C) 2015 by yieme, License: MIT

cacheman-multi's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.