Mercurial > bugzilla-dashboard
annotate js/modules/cache.js @ 102:00b02ba5236c
made all delegates have a dotted name (namespaced), modified black-box.js a bit
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Wed, 28 Apr 2010 20:06:26 -0700 |
parents | 00d23d6d41b4 |
children |
rev | line source |
---|---|
93
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
1 Require.modules["cache/html5"] = function(exports, require) { |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
2 exports.create = function create(name, storage) { |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
3 var cache = storage.getItem(name); |
66 | 4 |
93
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
5 if (cache) |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
6 cache = JSON.parse(cache); |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
7 else |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
8 cache = {}; |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
9 |
93
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
10 return { |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
11 set: function set(key, value) { |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
12 cache[key] = value; |
75 | 13 |
93
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
14 // Remove the key first, to get around a strange iPad |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
15 // issue: http://stackoverflow.com/questions/2603682/is-anyone-else-receiving-a-quota-exceeded-err-on-their-ipad-when-accessing-locals |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
16 storage.removeItem(name); |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
17 |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
18 // TODO: We should really catch QUOTA_EXCEEDED_ERR here, |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
19 // which could be thrown if the user is in private |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
20 // browsing mode. |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
21 storage.setItem(name, JSON.stringify(cache)); |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
22 }, |
75 | 23 |
93
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
24 get: function get(key) { |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
25 return cache[key]; |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
26 }, |
78 | 27 |
93
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
28 clear: function clear() { |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
29 storage.removeItem(name); |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
30 cache = {}; |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
31 } |
00d23d6d41b4
made cache module into cache/html5 and a factory function.
Atul Varma <avarma@mozilla.com>
parents:
81
diff
changeset
|
32 }; |
78 | 33 }; |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
34 }; |