1.0.4 • Published 6 years ago

koa-filestore v1.0.4

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

koa-filestore

a FileStore use flat-cache for koa-session.

Suggested to use for:

  • The amount of your site's users is not very large.
  • Has sensitive session contents that can not store in cookie (e.g. some tokens).

Not suggested to use for:

  • The amount of your site's users is very large.
  • No sensitive session contents that can not store in cookie.

requirement

  • node.js@8.x (es6)
  • koa@2.x

use

const Koa = require('koa');
const FileStore = require('koa-filestore');
const session = require('koa-session');
const path = require('path');
const app = new Koa();

app.use(session(app, {
  // other session config
  store: new FileStore({
    cacheDir: path.resolve(__dirname, './session/'), // Dir to store session files, unencrypted.
    maxAge: 86400000, // Default maxAge for session, used if the maxAge of `koa-session` is undefined, avoid the session's key in cookies is stolen.
  })
}));

Tips

Every session key will generate a file in the cacheDir, so maybe you will clean the old files after some days.

You can make a timed task of shell script to clean them (e.g. delete files that last update is before 30 days).

some example, for reference only:

/root/soft_shell/clean-cache.sh:

#!/bin/sh
find /app/cacheDir/ -mtime +30 -name "*.*" -exec rm -Rf {} \;

crontab:

crontab -l
10 4 1 * * /bin/sh /root/soft_shell/clean-cache.sh
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago