node package manager

sessioncache-express

sessioncache-express

[![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url]

Installation for local usage for testing purposes

$ npm install sessioncache-express

Configuration of your Bluemix Node.js application

Add to your application's package.json's dependency section

"sessioncache-express" : "1.0.0"

Description

This is an implementation of a data store for the express-session module using the Data Cache service available on IBM Bluemix.

If you are not running your application on Bluemix, a very simple in-memory session table will be used. There are several options available to customize the behavior of both the session store and the backing Data Cache service instance.

Implementation

Implementation is very straightforward. The necessary requires in your express application:

var session = require('express-session');
var SessionCacheStore = require('sessioncache-express')(session);

The configuration of the express-session middleware itself:

var options = { mapname: 'mydatacachemap',
                eviction: 'LAT',
                ttl: 300,
                fallbackMemoryStore: false};
 
app.use(session(
        {store: new SessionCacheStore(options),
         secret: 'toomanysecrets'}
        ));

Options

Options has four recognized properties, but defaults are provided for all properties.

  • mapname Defines the map to be used on the Data Cache grid so you can control where the session keys/values are stored in the service.
  • eviction Defines how sessions are evicted should the cache run out of space. Eviction by last access time (LAT) is the default, but LUT (last update time) is also another option.
  • ttl Defines how long an entry should remain in the backing Data Cache instance. This is effectively your session expiration duration. If left blank, no TTL will be used and sessions will only be purged as space is needed in the cache.
  • fallbackMemoryStore When set to true, will fallback to using express-session's default in-memory implementation if the application is not running in the Bluemix environment. This is useful for removing the specific sessioncache-express functionality for debugging, or just to get a new app up and running.

Contributors

Please report issues to routlaw@us.ibm.com