Local session storage for Koa sessions using async/await v1.0.4
This is an implementation of the koa-session storage in local system memory. This is intended to be used as in-memory session storage for testing/development purposes, as none of the data is persisted to permanent storage.
Table of Contents
npm install --save koa-session-local
yarn add koa-session-local
koa-session-local works with koa-session (a simple session middleware for Koa),
and requires Node >= 7.6 for async/await support.
const koa = ;const session = ;const store = ;const app = ;appkeys = 'keys' 'keykeys';app;app;app;
The module will use the default, or user provided values for
maxAge parameters, as well as verify whether a
session is a rolling session, force save session, or otherwise.
Garbage collection is an important feature of many session management implementations in NodeJS and other platforms. In this module, we're provided options for you to control the frequency and other properties of the garbage collection.
Garbage collection is performed on session.get, so there may be a slight request delay when the session garbage collection has been initiated.
When a session is loaded, a mathematical check is performed against the probability value to determine if there should be a garbage collection cycle. If the generated number is less than the 'probability' value, then the sessions in the store are scanned for deletion. If the expiry date for an offer is passed, along with the 'maxlifetime' value, the sessions are removed.
Note: Using this function with a sufficiently low
maxlifetime value, in conjunction with other
may remove active or recently expired sessions that are not normally ready for garbage collection.
gc(bool): Enable or disable session garbage collection (gc)
probability(float): The probability for which session gc will be triggered, higher is more frequently
maxlifetime(int): The is the maximum lifetime in milliseconds after the session expiry a session can live, before it is removed
debug(fn()): A reference to a function to generate log information (optional)
const defaults =gc: falseprobability: 005 /* 5% chance per session.get call */maxlifetime: 60 * 1000 /* 60s in ms */
gc and use the default values with no debugging:
gc and configure other properties:
MIT © Justin Mitchell (2019)