npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-session-local

v1.0.4

Published

Local session storage for Koa sessions

Downloads

6

Readme

koa-session-local

NPM version build status David deps David devDeps node version npm download

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.

NPM

Table of Contents

Install

npm:

npm install --save koa-session-local

yarn:

yarn add koa-session-local

Usage

koa-session-local works with koa-session (a simple session middleware for Koa), and requires Node >= 7.6 for async/await support.

Basic

const koa = require('koa');
const session = require('koa-session');
const store = require('koa-session-local');

const app = koa();
app.keys = ['keys', 'keykeys'];
app.use(session({
    store: new store(),
    ...
}));

app.use(async ctx => {
    const { session } = ctx;
    let n = session.views || 0;
    session.views = ++n;
    ctx.body = `${n} view(s)`;
});

app.listen(3000);

Options

The module will use the default, or user provided values for age and maxAge parameters, as well as verify whether a session is a rolling session, force save session, or otherwise.

Garbage collection

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 koa-session settings may remove active or recently expired sessions that are not normally ready for garbage collection.

Options

  • 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)

Defaults:

const defaults = {
    gc: false,
    probability: 0.05, /* 5% chance per session.get call */
    maxlifetime: 60 * 1000 /* 60s in ms */
}

To use:

Enable gc and use the default values with no debugging:

app.use(session({
    store: new store({
         gc: true
     }),
    ...
}));

Enable gc and configure other properties:

app.use(session({
    store: new store({
         gc: true,
         probability: 0.05, /* 5% change */
         maxlifetime: 60 * 1000, /* 60 seconds */
         debug: console.log /* debug messages will be sent to console.log */
     }),
    ...
}));

License

MIT © Justin Mitchell (2019)

Contributors

contrib-jmitchell38488