forked from marcuswestin/store.js
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexpire.js
More file actions
37 lines (31 loc) · 744 Bytes
/
expire.js
File metadata and controls
37 lines (31 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var namespace = 'expire_mixin'
module.exports = expirePlugin
function expirePlugin() {
var expirations = this.namespace(namespace)
return {
set: expire_set,
get: expire_get,
remove: expire_remove
}
function expire_set(super_fn, key, val, expiration) {
if (!this.hasNamespace(namespace)) {
expirations.set(key, expiration)
}
return super_fn()
}
function expire_get(super_fn, key) {
if (!this.hasNamespace(namespace)) {
var expiration = expirations.get(key, Number.MAX_VALUE)
if (expiration <= new Date().getTime()) {
this.remove(key)
}
}
return super_fn()
}
function expire_remove(super_fn, key) {
if (!this.hasNamespace(namespace)) {
expirations.remove(key)
}
return super_fn()
}
}