seneca-vcache

versioned caching plugin for seneca

npm install seneca-vcache
18 downloads in the last week
30 downloads in the last month

seneca-vcache

Node.js Seneca Versioned Caching module

This module is a plugin for the Seneca framework. It provides a data caching mechanism for Seneca data entities. Using this module will give your Seneca app a big performance boost.

The caching mechanism goes beyond simple key-based caching using memcached. In addition, a smaller "hot" cache is maintained within the Node process. Data entities are given transient version numbers, and these are used to synchronize the hot cache with memcached.

This is plays nicely with multiple memcached instances, and allows Seneca apps to scale.

(See chapter 8 of my book for details, or read How key-based cache expiration works)

Support

If you're using this module, feel free to contact me on twitter if you have any questions! :) @rjrodger

Current Version: 0.2.2

Tested on: Node 0.10.6, 0.8.7, Seneca 0.5.9

Quick example

This module works by wrapping the data entity actions (role:entity, cmd:save, ... etc). You just need to register it:

var seneca = require('seneca')()
seneca.use('memcached')
seneca.use('vcache')

Then just use data entities as normal. Except things will be a lot faster.

Install

npm install seneca
npm install seneca-memcached
npm install seneca-vcache

You'll need the seneca-memcached plugin as a dependency.

You'll also need memcached

Actions

plugin:vcache, cmd:stats

Returns a JSON object containing the current hit/miss counts of the cache.

Options

Here's how to set the options (the values shown are the defaults):

seneca.use('vcache',{
  prefix:  'seneca-vcache',
  maxhot:  1111,
  expires: 3600
})

Where:

  • prefix: prefix string to namespace your cache (useful if your cache is used by other things)
  • maxhot: the maximum number of hot items to store in the running node process memory
  • expires: how long to store items (in seconds)

Test

cd test
mocha store.test.js --seneca.log.print

Also

cd test
memcached -vv
mongod --dbpath=db
node n1.js --seneca.log=type:plugin
node n2.js --seneca.log=type:plugin
npm loves you