Skip to content

Commit cbfe8d7

Browse files
committed
add ttl support for default memory store
1 parent 48f037a commit cbfe8d7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/memory_store.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
module.exports = class MemoryStore {
22
constructor() {
33
this.sessions = {}
4+
this.timeouts = {}
45
}
56

67
get(sid) {
78
return this.sessions[sid]
89
}
910

10-
set(sid, val, ttl) { // eslint-disable-line no-unused-vars
11+
set(sid, val, ttl) {
1112
this.sessions[sid] = val
13+
14+
if (sid in this.timeouts) clearTimeout(this.timeouts[sid])
15+
this.timeouts[sid] = setTimeout(this.destroy.bind(this, sid), ttl)
1216
}
1317

1418
destroy(sid) {
1519
delete this.sessions[sid]
20+
delete this.timeouts[sid]
1621
}
1722
}

0 commit comments

Comments
 (0)