Mercurial > bugzilla-dashboard
annotate 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 |
rev | line source |
---|---|
66 | 1 Require.modules["cache"] = function(exports, require) { |
78 | 2 const CACHE_NAME = "cache"; |
3 | |
66 | 4 var window = require("window"); |
78 | 5 var cache = window.localStorage.getItem(CACHE_NAME); |
66 | 6 |
75 | 7 if (cache) |
8 cache = JSON.parse(cache); | |
9 else | |
66 | 10 cache = {}; |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
11 |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
12 exports.set = function set(key, value) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
13 cache[key] = value; |
75 | 14 |
15 // Remove the key first, to get around a strange iPad | |
16 // issue: http://stackoverflow.com/questions/2603682/is-anyone-else-receiving-a-quota-exceeded-err-on-their-ipad-when-accessing-locals | |
78 | 17 window.localStorage.removeItem(CACHE_NAME); |
75 | 18 |
19 // TODO: We should really catch QUOTA_EXCEEDED_ERR here, | |
20 // which could be thrown if the user is in private | |
21 // browsing mode. | |
78 | 22 window.localStorage.setItem(CACHE_NAME, JSON.stringify(cache)); |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
23 }; |
78 | 24 |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
25 exports.get = function get(key) { |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
26 return cache[key]; |
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
27 }; |
78 | 28 |
29 exports.clear = function clear() { | |
30 window.localStorage.removeItem(CACHE_NAME); | |
31 cache = {}; | |
32 }; | |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
33 }; |