session-gdatastore v1.0.5
session-gdatastore
Express session store managed by Google Datastore
Installing
Add to your application via npm:
npm i session-gdatastore --save
This will install session-gdatastore and add it to your application's package.json file.
How to use
Use with your express session middleware, like this:
var express = require('express');
var app = module.exports = express();
var session = require('express-session');
var DataStoreSession = require('session-gdatastore')(session);
var options = {
autoRemoveInterval: 20000,
entity:'entity',
expiration: 15000,
namespace: 'namespace',
projectId:'projectId',
touchAfter: 24 * 3600
};
var sessionStore = new DataStoreSession(options);
app.use(session({
key: 'session_cookie_name',
secret: 'session_cookie_secret',
store: sessionStore,
resave: false,
saveUninitialized: false
}));
Default options
The session-gdatastore will use for default this parameters:
var defaultOptions = {
autoRemoveInterval: 900000,
expiration: 86400000,
entity: 'session'
};
Lazy session update
If you are using express-session >= 1.10.0 and don't want to resave all the session on database every single time that the user refresh the page, you can lazy update the session, by limiting a period of time.
app.use(express.session({
secret: 'secret',
saveUninitialized: false, // don't create session until something stored
resave: false, //don't save session if unmodified
store: new DataStoreSession({
touchAfter: 24 * 3600 // time period in seconds
})
}));
by doing this, setting touchAfter with the value 24 * 3600 you are saying to the session be updated only one time in a period of 24 hours, does not matter how many request's are made (with the exception of those that change something on the session data)
Authors
- Diego Fonseca M. (https://github.com/dfonsecam)
- Jean Murillo A. (https://github.com/jeancamurillo)
License
This project is licensed under the Apache License - see the LICENSE file for details