Mercurial > bugzilla-dashboard
annotate js/modules/cache.js @ 82:03bf0a1b85da
made 'storage' point to sessionStorage instead of localStorage
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Mon, 26 Apr 2010 04:32:50 -0700 |
parents | e3de1fe32f40 |
children | 00d23d6d41b4 |
rev | line source |
---|---|
66 | 1 Require.modules["cache"] = function(exports, require) { |
78 | 2 const CACHE_NAME = "cache"; |
3 | |
81
e3de1fe32f40
made cache module require 'storage' instead of 'window'
Atul Varma <avarma@mozilla.com>
parents:
78
diff
changeset
|
4 var storage = require("storage"); |
e3de1fe32f40
made cache module require 'storage' instead of 'window'
Atul Varma <avarma@mozilla.com>
parents:
78
diff
changeset
|
5 var cache = storage.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 | |
81
e3de1fe32f40
made cache module require 'storage' instead of 'window'
Atul Varma <avarma@mozilla.com>
parents:
78
diff
changeset
|
17 storage.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. | |
81
e3de1fe32f40
made cache module require 'storage' instead of 'window'
Atul Varma <avarma@mozilla.com>
parents:
78
diff
changeset
|
22 storage.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() { | |
81
e3de1fe32f40
made cache module require 'storage' instead of 'window'
Atul Varma <avarma@mozilla.com>
parents:
78
diff
changeset
|
30 storage.removeItem(CACHE_NAME); |
78 | 31 cache = {}; |
32 }; | |
47
0b71df72ebe1
integrated dashboard into main.html.
Atul Varma <avarma@mozilla.com>
parents:
diff
changeset
|
33 }; |