Socket
Book a DemoInstallSign in
Socket

cacheswitcher

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

cacheswitcher

cacheswitcher ==========

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

cacheswitcher

This library is a wrapper around https://github.com/groupon/node-cached and https://github.com/cayasso/cacheman-redis, it makes easy to switch from one to the other with configuration. It also make all APIs the same, same methods, same parameters. Not all APIs are wrapped but the common ones. It also add the Promise style on all the method

Supported APIs

  • set which set a value
    • key: string as the unique key to set
    • value: any type that you want to store
    • ttl: string that represent the time to live like 3d -> 3 days, 1h -> 1 hour ...
  • get
    • key: string as the unique key to retrieve
  • unset
    • key: string as the unique key to remove

Install

npm install supercache

usage

Simple memory cache


var superCache = require(cacheswitcher)('memory');
superCache.set('mykey',12345).then(function(){
    superCache.get('mykey').then(function(data){
        console.log(data);
        superCache.unset('mykey').then(function(){
            console.log('Clean');
        });
    })
})

Redis cache


var superCache = require(cacheswitcher)('redis',{server:'127.0.0.1',port:6379});
superCache.set('mykey',12345).then(function(){
    superCache.get('mykey').then(function(data){
        console.log(data);
        superCache.unset('mykey').then(function(){
            console.log('Clean');
        });
    })
})

Redis cache with ttl


var superCache = require(cacheswitcher)('redis',{server:'127.0.0.1',port:6379});
superCache.set('mykey',12345,'3d').then(function(){
    //3 days later
    superCache.get('mykey').then(function(data){
        console.log(data); // -> undefined
        superCache.unset('mykey').then(function(){
            console.log('Clean');
        });
    })
})

Constructor

  • type: string like memory | redis
  • opt: Object with following properties
    • server: only for redis
    • port: only for redis
    • name: only for memory namespace

Test

FAQs

Package last updated on 22 Feb 2018

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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.