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:
Nick Winter 2015-04-18 17:25:40 -07:00
parent b358296120
commit a1199a0121
2 changed files with 18 additions and 6 deletions

View file

@ -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)
return null unless s
try
@ -8,8 +10,17 @@ module.exports.load = (key) ->
console.warn('error loading from storage', key)
return null
module.exports.save = (key, value) ->
s = JSON.stringify(value)
localStorage.setItem(key, s)
# Pass 0 for expirationInMinutes to persist it as long as possible outside of lscache expiration.
module.exports.save = (key, value, expirationInMinutes) ->
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

View file

@ -47,7 +47,8 @@
"modernizr": "~2.8.3",
"backfire": "~0.3.0",
"fastclick": "~1.0.3",
"three.js": "*"
"three.js": "*",
"lscache": "~1.0.5"
},
"overrides": {
"backbone": {