-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ContextStore #80
Add ContextStore #80
Conversation
1 similar comment
65e4f3d
to
89d5c14
Compare
89d5c14
to
1d59173
Compare
ping @dead-horse |
1d59173
to
e008b72
Compare
1 similar comment
index.js
Outdated
assert(typeof opts.store.set === 'function', 'store.set must be function'); | ||
assert(typeof opts.store.destroy === 'function', 'store.destroy must be function'); | ||
if (opts.ContextStore) { | ||
assert(typeof opts.ContextStore === 'function', 'ContextStore must be a function'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is.class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And check ContextStore.prototype[method]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only check ContextStore.prototype[method]
once
@@ -78,10 +78,8 @@ function formatOpts(opts) { | |||
opts.decode = util.decode; | |||
} | |||
|
|||
if (opts.store) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check store first when it's specified.
lib/context.js
Outdated
if (this.store) { | ||
assert(typeof this.store.get === 'function', 'store.get must be function'); | ||
assert(typeof this.store.set === 'function', 'store.set must be function'); | ||
assert(typeof this.store.destroy === 'function', 'store.destroy must be function'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check store type on every request.
Only assert once at the beginning.
test/store.test.js
Outdated
@@ -6,635 +6,654 @@ const should = require('should'); | |||
const mm = require('mm'); | |||
const session = require('..'); | |||
const store = require('./store'); | |||
const ContextStore = require('./context_store'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep the old test file and add a new one for context store.
e008b72
to
4703d0b
Compare
All issues settled |
should introduce |
4703d0b
to
d86f898
Compare
@@ -118,6 +118,8 @@ app.use(convert(session(app))); | |||
|
|||
Once you passed `options.store`, session is strong dependent on your external store, you can't access session if your external store is down. **Use external session stores only if necessary, avoid use session as a cache, keep session lean and stored by cookie!** | |||
|
|||
If your session store requires data or utilities from context, `opts.ContextStore` is alse supported. `ContextStore` must be a class which claims three instance methods demonstrated above. `new ContextStore(ctx)` will be executed on every request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
LGTM |
@shaoshuai0102 please pick this feature to master branch |
publish a version pls. I will pick it to master |
|
No description provided.