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

express-memfilestore

v1.7.1

Published

express-session full featured MemoryStore layer without leaks! Allows persisting sessions to disk.

Downloads

9

Readme

Express-MemFileStore

express-session full featured MemoryStore module without leaks! This fork of MemoryStore allows sessions to be persisted to the disk.

A session store implementation for Express using lru-cache.

Because the default MemoryStore for express-session will lead to a memory leak due to it haven't a suitable way to make them expire.

The sessions are still stored in memory, so they're not shared with other processes or services. The sessions will also be persisted to the disk.

Setup

$ npm install express-session express-memfilestore

Pass the express-session store into express-memfilestore to create a MemoryStore constructor.

const session = require('express-session')
const MemFileStore = require('express-memfilestore')(session)

app.use(session({
    cookie: { maxAge: 86400000 },
    store: new MemFileStore({
      checkPeriod: 86400000, // prune expired entries every 24h
	  savePeriod: 300000, // saves sessions to disk every 5m
	  saveFile: path.join(__dirname, 'sessions.json')
    }),
    resave: false,
    secret: 'keyboard cat'
}))

Options

  • checkPeriod Define how long MemFileStore will check for expired. The period is in ms.
  • savePeriod Sets how often MemFileStore will save sessions to disk. This is in ms.
  • saveFile The file that MemFileStore will save the sessions to. If this is in a directory, the directory must already exist.
  • max The maximum size of the cache, checked by applying the length function to all values in the cache. It defaults to Infinity.
  • ttl Session TTL (expiration) in milliseconds. Defaults to session.maxAge (if set), or one day. This may also be set to a function of the form (options, sess, sessionID) => number.
  • dispose Function that is called on sessions when they are dropped from the cache. This can be handy if you want to close file descriptors or do other cleanup tasks when sessions are no longer accessible. Called with key, value. It's called before actually removing the item from the internal cache, so if you want to immediately put it back in, you'll have to do that in a nextTick or setTimeout callback or it won't do anything.
  • stale By default, if you set a maxAge, it'll only actually pull stale items out of the cache when you get(key). (That is, it's not pre-emptively doing a setTimeout or anything.) If you set stale:true, it'll return the stale value before deleting it. If you don't set this, then it'll return undefined when you try to get a stale entry, as if it had already been deleted.
  • noDisposeOnSet By default, if you set a dispose() method, then it'll be called whenever a set() operation overwrites an existing key. If you set this option, dispose() will only be called when a key falls out of the cache, not when it is overwritten.
  • serializer An object containing stringify and parse methods compatible with Javascript's JSON to override the serializer used.

Methods

MemFileStore implements all the required, recommended and optional methods of the express-session store. Plus a few more:

  • startInterval() and stopInterval() methods to start/clear the automatic check for expired. startSaveInterval() and stopSaveInterval() methods start/stop the session saving.

  • prune() that you can use to manually remove only the expired entries from the store.

Debug

To enable debug set the env var DEBUG=MemFileStore