annotate js/modules/cache.js @ 100:c486d35fad27

added more mocks; black-box now talks to a really simple fake bugzilla 'server'.
author Atul Varma <avarma@mozilla.com>
date Tue, 27 Apr 2010 23:06:29 -0700
parents 00d23d6d41b4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
55c1b3647357 cache now uses localstorage
Atul Varma <avarma@mozilla.com>
parents: 47
diff changeset
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
312d4af344c2 Fixed cache.js for iPad.
Atul Varma <avarma@mozilla.com>
parents: 66
diff changeset
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
312d4af344c2 Fixed cache.js for iPad.
Atul Varma <avarma@mozilla.com>
parents: 66
diff changeset
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
4bb45ff5788a added repair dialog
Atul Varma <avarma@mozilla.com>
parents: 75
diff changeset
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
4bb45ff5788a added repair dialog
Atul Varma <avarma@mozilla.com>
parents: 75
diff changeset
33 };
47
0b71df72ebe1 integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff changeset
34 };