Fixed #343. Fixed #2565. localStorage cache now only lasting a week for most items, using lscache (bower install, y'all).
This commit is contained in:
parent
b358296120
commit
a1199a0121
2 changed files with 18 additions and 6 deletions
|
@ -1,4 +1,6 @@
|
||||||
module.exports.load = (key) ->
|
# Pass false for fromCache to fetch keys that have been stored outside of lscache.
|
||||||
|
module.exports.load = (key, fromCache=true) ->
|
||||||
|
return lscache.get key if fromCache
|
||||||
s = localStorage.getItem(key)
|
s = localStorage.getItem(key)
|
||||||
return null unless s
|
return null unless s
|
||||||
try
|
try
|
||||||
|
@ -8,8 +10,17 @@ module.exports.load = (key) ->
|
||||||
console.warn('error loading from storage', key)
|
console.warn('error loading from storage', key)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
module.exports.save = (key, value) ->
|
# Pass 0 for expirationInMinutes to persist it as long as possible outside of lscache expiration.
|
||||||
s = JSON.stringify(value)
|
module.exports.save = (key, value, expirationInMinutes) ->
|
||||||
localStorage.setItem(key, s)
|
expirationInMinutes ?= 7 * 24 * 60
|
||||||
|
if expirationInMinutes
|
||||||
|
lscache.set key, value, expirationInMinutes
|
||||||
|
else
|
||||||
|
localStorage.setItem key, JSON.stringify(value)
|
||||||
|
|
||||||
module.exports.remove = (key) -> localStorage.removeItem key
|
# Pass false for fromCache to remove keys that have been stored outside of lscache.
|
||||||
|
module.exports.remove = (key, fromCache=true) ->
|
||||||
|
if fromCache
|
||||||
|
lscache.remove key
|
||||||
|
else
|
||||||
|
localStorage.removeItem key
|
||||||
|
|
|
@ -47,7 +47,8 @@
|
||||||
"modernizr": "~2.8.3",
|
"modernizr": "~2.8.3",
|
||||||
"backfire": "~0.3.0",
|
"backfire": "~0.3.0",
|
||||||
"fastclick": "~1.0.3",
|
"fastclick": "~1.0.3",
|
||||||
"three.js": "*"
|
"three.js": "*",
|
||||||
|
"lscache": "~1.0.5"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"backbone": {
|
"backbone": {
|
||||||
|
|
Reference in a new issue