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