Session docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 047499d · Browse files · 3 files·+73 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+73 added−12 removed
- other:+73 added−12 removed
Provenance
- Commit
9d5a6f9- Tree
8f0db84- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
047499d
3 files changed+73 added−12 removed
modified:examples/chat/app.js+5 added-1 removed
6 unmodified lines7891011111213141554 unmodified lines7071727374757677786 unmodified lines use(MethodOverride) use(ContentLength) use(CommonLogger) use(Cookie) use(Session, { reapInterval: 10000, expires: 60000 }) use(Session) set('root', dirname(__filename)) enable('cache static files') //enable('cache view contents')})54 unmodified linesget('/simple', function(){ return 'Hello :)'})
get('/favicon.ico', function(){ this.halt()})
run()No newline at end of fileNo newline at end of filemodified:lib/express/plugins/session.js+67 added-10 removed
1 2 // Express - Session - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4+// --- Session5+6 var Session = Class({7+ 8+ /**9+ * Initialize session _sid_.10+ */11+ 12 init: function(sid) {13 this.id = sid14 this.touch()15 },16 17+ /**18+ * Update last access time.19+ *20+ * @api private21+ */22+ 23 touch: function() {24 this.lastAccess = Number(new Date)12- require('sys').p('touched ' + this.id)25 }26 })27 28+// --- MemoryStore29+30 exports.MemoryStore = Class({31+ 32+ /**33+ * Initialize in-memory session store.34+ */35+ 36 init: function() {37 this.store = {}38 },39 40+ /**41+ * Fetch session with the given _sid_ or 42+ * a new Session is returned.43+ *44+ * @param {int} sid45+ * @return {Session}46+ * @api private47+ */48+ 49 fetch: function(sid) {50 return this.store[sid] || new Session(sid)51 },52 53+ /**54+ * Commit _session_ data.55+ *56+ * @param {Session} session57+ * @api private58+ */59+ 60 commit: function(session) {61 return this.store[session.id] = session62 },63 64+ /**65+ * Clear all sessions.66+ *67+ * @api public68+ */69+ 70 clear: function() {71 this.store = {}72 },73 74+ /**75+ * Destroy session using the given _sid_.76+ *77+ * @param {int} sid78+ * @api public79+ */80+ 81 destroy: function(sid) {34- require('sys').p('destroying ' + sid)35- require('sys').p(this.store[sid])82 delete this.store[sid]83 },84 85+ /**86+ * Reap sessions older than _ms_.87+ *88+ * @param {int} ms89+ * @api private90+ */91+ 92 reap: function(ms) {93 var threshold = Number(new Date(Number(new Date) - ms))41- require('sys').p('reaping less than ' + threshold + ' ms')94 for (var sid in this.store)95 if (this.store.hasOwnProperty(sid))96 if (this.store[sid].lastAccess < threshold)97 this.destroy(sid)4 unmodified lines102 extend: {103 104 /**105 * Initialize memory store and start reaper.106+ *107+ * Options:108+ *109+ * - lifetime lifetime of session in milliseconds, defaults to one day110+ * - reapInterval interval in milliseconds in which to reap old sessions, defaults to one hour111+ * 112+ * @param {hash} options113+ * @api private114 */115 116 init: function(options) {117 process.mixin(this, options)1 unmodified line119 this.startReaper()120 },121 122 /**63- * Start reaping123+ * Start reaper.124 *65- * @param {Type} Var66- * @return {Type}67- * @api public125+ * @api private126 */127 128 startReaper: function() {129 var self = this,130 oneDay = 86400000,131 oneHour = 3600000132 setInterval(function(){75- require('sys').p('reaping')76- self.store.reap(self.expires || self.maxAge || oneDay)133+ self.store.reap(self.lifetime || oneDay)134 }, self.reapInterval || oneHour)135 }136 },137 25 unmodified linesmodified:lib/express.js+1 added-1 removed
3 unmodified lines4567883 unmodified linesrequire.paths.unshift(path.dirname(__filename) + '/support/ejs/lib')require.paths.unshift(path.dirname(__filename) + '/support/haml/lib')require.paths.unshift(path.dirname(__filename) + '/support/sass/lib')require('oo')require('express/core')require('express/core')No newline at end of file