Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-service-node-cache

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-service-node-cache

A node-cache plugin for cache-service.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
149
decreased by-29.72%
Maintainers
1
Weekly downloads
 
Created
Source

cache-service-node-cache

  • A node-cache plugin for cache-service
  • AND a standalone node-cache wrapper

Basic Usage

Require and instantiate

var csNodeCache = require('cache-service-node-cache');

var cacheModuleConfig = {defaultExpiration: 60};
var nodeCache = new csNodeCache(cacheModuleConfig);

Cache!

nodeCache.set('key', 'value');

Benefits of Using cache-service-node-cache

If you're using cache-service-node-cache with cache-service, the benefits are obvious. However, there are also a couple of reasons you might prefer it to using vanilla node-cache:

  • It adds an excellent .mset() implementation which allow you to set expirations on a per key, per function call, and/or per cache-service-node-cache instance basis (Vanilla node-cache does not offer .mset() at all).
  • Built-in logging with a verbose flag.

Cache Module Configuration Options

type

An arbitrary identifier you can assign so you know which cache is responsible for logs and errors.

  • type: string
  • default: 'node-cache'

defaultExpiration

The expiration to include when executing cache set commands. Can be overridden via .set()'s optional expiraiton param.

  • type: int
  • default: 900
  • measure: seconds

verbose

When used with cache-service, this property is overridden by cache-service's verbose value.

When false, cache-service-node-cache will log only errors. When true, cache-service-node-cache will log all activity (useful for testing and debugging).

  • type: boolean
  • default: false

API

Although this is a node-cache wrapper, its API differs in some small cases from node-cache's own API because all cache-service-compatible cache modules match cache-service's API.

.get(key, callback (err, response))

Retrieve a value by a given key.

  • key: type: string
  • callback: type: function
  • err: type: object
  • response: type: string or object

.mget(keys, callback (err, response))

Retrieve the values belonging to a series of keys. If a key is not found, it will not be in response.

  • keys: type: an array of strings
  • callback: type: function
  • err: type: object
  • response: type: object, example: {key: 'value', key2: 'value2'...}

.set(key, value [, expiraiton, callback])

Set a value by a given key.

  • key: type: string
  • callback: type: function
  • expiration: type: int, measure: seconds
  • callback: type: function

.mset(obj [, expiration, callback])

Set multiple values to multiple keys

  • obj: type: object, example: {'key': 'value', 'key2': 'value2', 'key3': {cacheValue: 'value3', expiration: 60}}
  • callback: type: function

This function exposes a heirarchy of expiration values as follows:

  • The expiration property of a key that also contains a cacheValue property will override all other expirations. (This means that, if you are caching an object, the string 'cacheValue' is a reserved property name within that object.)
  • If an object with both cacheValue and expiration as properties is not present, the expiration provided to the .mset() argument list will be used.
  • If neither of the above is provided, each cache's defaultExpiration will be applied.

.del(keys [, callback (err, count)])

Delete a key or an array of keys and their associated values.

  • keys: type: string || array of strings
  • callback: type: function
  • err: type: object
  • count: type: int

.flush([cb])

Flush all keys and values from.

  • callback: type: function

More Node-Cache Methods

If you need access to one of node-cache's other functions, you can get at the underlying node-cache instance by tapping into the .db property like so:

var underlyingNodeCacheInstance = nodeCacheModule.db;
underlyingNodeCacheInstance.SOME_OTHER_NODE_CACHE_FUNCTION();

Keywords

FAQs

Package last updated on 10 Jul 2015

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc