Skip to content

senecajs/seneca-entity-cache

Repository files navigation

@seneca/entity-cache

Seneca plugin providing simple id-based distributed entity caching.

Voxgig This open source module is sponsored and supported by Voxgig.

Install

npm install seneca
npm install seneca-memcached-cache
npm install @seneca/entity-cache

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

You'll also need memcached

Or... you can use redis: seneca-redis-cache.

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-cache')
seneca.use('entity-cache')

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

More Examples

See test/ for usage examples.

Motivation

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 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 are having difficulty, open an issue on the GitHub repo.

API

  • prefix : string "SE"
  • maxhot : number 1111
  • maxage : number 22222
  • expires : number 3600
  • hot : boolean true

Set plugin options when loading with:

seneca.use('entity-cache', { name: value, ... })

Note: foo.bar in the list above means { foo: { bar: ... } }

« clear:hot-keys,plugin:entity-cache »

No description provided.


« get:stats,plugin:entity-cache »

No description provided.


« list:hot-keys,plugin:entity-cache »

No description provided.


Options

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

seneca.use('entity-cache',{
  prefix:  '@seneca/entity-cache',
  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)

Contributing

The Senecajs org encourages open participation. If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.

Running tests

The unit tests require a running memcached and redis.

cd test
mocha *.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

Background

This plugin provides id-based distributed entity caching for the Seneca framework.

Seneca plugin providing simple id-based distributed entity caching. Npm Travis Coveralls Maintainability DeepScan grade dependencies Status Gitter BadgeCoveralls: https://coveralls.io/repos/senecajs/seneca-entity-cache/badge.svg?branch=master&service=github BadgeNpm: https://badge.fury.io/js/%40seneca%2Fentity-cache.svg BadgeTravis: https://travis-ci.org/senecajs/seneca-entity-cache.svg?branch=master Coveralls: https://coveralls.io/github/senecajs/seneca-entity-cache?branch=master Npm: https://www.npmjs.com/package/seneca-entity-cache Travis: https://travis-ci.org/senecajs/seneca-entity-cache?branch=master gitter-badge: https://badges.gitter.im/Join%20Chat.svg gitter-url: https://gitter.im/senecajs/seneca

About

seneca-vcache

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt

Code of conduct

Stars

5 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors