Mercurial > bugzilla-dashboard
comparison js/modules/cache.js @ 78:4bb45ff5788a
added repair dialog
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Sun, 25 Apr 2010 20:54:51 -0700 |
parents | 312d4af344c2 |
children | e3de1fe32f40 |
comparison
equal
deleted
inserted
replaced
77:00d2584cdd7b | 78:4bb45ff5788a |
---|---|
1 Require.modules["cache"] = function(exports, require) { | 1 Require.modules["cache"] = function(exports, require) { |
2 const CACHE_NAME = "cache"; | |
3 | |
2 var window = require("window"); | 4 var window = require("window"); |
3 var cache = window.localStorage.getItem("cache"); | 5 var cache = window.localStorage.getItem(CACHE_NAME); |
4 | 6 |
5 if (cache) | 7 if (cache) |
6 cache = JSON.parse(cache); | 8 cache = JSON.parse(cache); |
7 else | 9 else |
8 cache = {}; | 10 cache = {}; |
10 exports.set = function set(key, value) { | 12 exports.set = function set(key, value) { |
11 cache[key] = value; | 13 cache[key] = value; |
12 | 14 |
13 // Remove the key first, to get around a strange iPad | 15 // Remove the key first, to get around a strange iPad |
14 // issue: http://stackoverflow.com/questions/2603682/is-anyone-else-receiving-a-quota-exceeded-err-on-their-ipad-when-accessing-locals | 16 // issue: http://stackoverflow.com/questions/2603682/is-anyone-else-receiving-a-quota-exceeded-err-on-their-ipad-when-accessing-locals |
15 window.localStorage.removeItem("cache"); | 17 window.localStorage.removeItem(CACHE_NAME); |
16 | 18 |
17 // TODO: We should really catch QUOTA_EXCEEDED_ERR here, | 19 // TODO: We should really catch QUOTA_EXCEEDED_ERR here, |
18 // which could be thrown if the user is in private | 20 // which could be thrown if the user is in private |
19 // browsing mode. | 21 // browsing mode. |
20 window.localStorage.setItem("cache", JSON.stringify(cache)); | 22 window.localStorage.setItem(CACHE_NAME, JSON.stringify(cache)); |
21 }; | 23 }; |
24 | |
22 exports.get = function get(key) { | 25 exports.get = function get(key) { |
23 return cache[key]; | 26 return cache[key]; |
24 }; | 27 }; |
28 | |
29 exports.clear = function clear() { | |
30 window.localStorage.removeItem(CACHE_NAME); | |
31 cache = {}; | |
32 }; | |
25 }; | 33 }; |