Socket
Book a DemoInstallSign in
Socket

uber-cache-helpers

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uber-cache-helpers

getEngine from config.

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

uber-cache-helpers

The aim of uber-cache-helpers is to give a set of tools that lets the user choose a backend store directly from its application configuration.

Available backends

We have four backends at the moment:

  • Memory
  • Redis
  • Mongodb
  • Memcached

Configure the Memory backend

var options = {"engine": "memory"};

Configure the Redis backend

var options = {
  "engine": "redis",
  "settings": {
    "port": 6379,
    "host": "127.0.0.1",
    "db": "0"
  }
};

These are default values, so you can also simply use:

var options = {"engine": "redis"};

Configure the Memcached backend

var options = {
  "engine": "memcached",
  "settings": {
    "serverLocations": ["127.0.0.1:11211"]
  }
};

These are default values, so you can also simply use:

var options = {"engine": "memcached"};

Configure the MongoDB backend

var options = {
  "engine": "mongodb",
  "settings": {
    "collectionName": "testCollection",
    "connectionString": "mongodb://127.0.0.1:27017/uberCache"
  }
};

Get your Uber-Cache instance from the configuration

The aim of all of this is to be able to change the configuration and just have the same Uber-Cache API for all of them.

var getCacheBackend = require("uber-cache-helpers").getCacheBackend;

var cache = getCacheBackend(options);

cache.set("the key", "the value", function () {
  cache.get("the key", function (error, value) {
    console.log(value);
  });
});

And that's just it!

You can also get access directly to then engine using cache.engine:

cache.engine.close();

FAQs

Package last updated on 07 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts