Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including connect-datacache with all npm packages installed. Try it out:

var connectDatacache = require("connect-datacache")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

connect-datacache v1.1.0

Express session connector for IBM DataCache


NPM Version NPM Downloads Build Status

NodeJS express-session storage for IBM Bluemix Data Cache service.


npm install connect-datacache

Using the DataCache storage connector:

var session = require('express-session');
var DataCacheStore = require('connect-datacache')(session);

    store: new DataCacheStore(options),
    secret: 'keyboard cat'

Standard usage for Bluemix environment/dev environment - with fallback on MemoryStore:

dcStore = null;
try { 
    // by default is looking into bluemix cfenv services
    dcStore = new DataCacheStore();
} catch (err) {
    // log fallback on memory store for no DataCache service linked to app

    store: dcStore,
    secret: 'keyboard cat'

Storage Options

Bellow is an example with the full list of parameters - default values for optional ones:

var store = new DataCacheStore({
        // required parameters when no custom client provided or no ENV credentials are set
        restResource: '{gridName}',
        restResourceSecure: '{gridName}',
        gridName: '{gridName}',
        username: '{username}',
        password: '{password}',
        // optional parameters - default values
        mapName: '{gridName}',
        eviction: 'LUT',
        locking: 'optimistic',
        contentType: 'application/json',
        secure: true,
        ttl: 3600,
        prefix: 'sess:',
        cfServiceName: null,
        client: null

Bluemix environment

The datacache client is looking first for DataCache service cfenv values. For the Bluemix NodeJS app with a DataCache service associated the required parameters are read from ENV variables (credentials):

Environment Variables > VCAP_SERVICES

    "system_env_json": {
      "VCAP_SERVICES": {
         "DataCache-dedicated": [
               "credentials": {
                 "catalogEndPoint": "...",
                 "restResource": "http://ip-numeric/resources/datacaches/SYS_GENERATED_GRIDNAME",
                 "restResourceSecure": "",
                 "gridName": "SYS_GENERATED_GRIDNAME",
                 "username": "SYS_GENERATED_USERNAME",
                 "password": "SYS_GENERATED_PASSWORD"
               "name": "datacache-service-name",
               "tags": []


defaults: VCAP_SERVICES credentials values

Depending on the "secure" value, one of them is required if not found in ENV variables by cfenv.


For a Bluemix application it is required to have the same value as for "gridName". A resource is identified with a complete URI as:



For non-Bluemix environments it can be customized as a namespace for data.


  • 'LUT' - default - expires based on the Last Update Time
  • 'NONE' - data is stored indefinitly (until si programaticaly deleted)
  • 'LAT' - expires based on Last Access Time


  • 'optimistic' - default
  • 'pessimistic'


  • 'application/json' - default - turns on the JSON encoder/decoder for session data
  • other - saves session data as plain text


  • true - default - uses 'restResourceSecure' as store entrypoint
  • false - uses 'restResource' as store entrypoint


  • session/storage time to live - overrides the cookie maxAge value if present


  • custom prefix to be appended for all session keys


  • allows using multiple Data Cache services for same application - loads credentials from ENV using service name;
var store = new DataCacheStore({'cfenvServiceName': 'datacache-service-name'});


  • offers option to pass an instance of DataCacheClient or inteface matching object -> turns optional all the required parameters/credentials


  • PR code needs to pass the lint check and unit test
npm test
  • PR code should be covered by UT
npm run coverage




  • The connect-datacache code is based on implementation from other express-session storages as: connect-redis
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free