diff 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
line wrap: on
line diff
--- a/js/modules/cache.js	Sun Apr 25 19:47:53 2010 -0700
+++ b/js/modules/cache.js	Sun Apr 25 20:54:51 2010 -0700
@@ -1,6 +1,8 @@
 Require.modules["cache"] = function(exports, require) {
+  const CACHE_NAME = "cache";
+
   var window = require("window");
-  var cache = window.localStorage.getItem("cache");
+  var cache = window.localStorage.getItem(CACHE_NAME);
 
   if (cache)
     cache = JSON.parse(cache);
@@ -12,14 +14,20 @@
 
     // Remove the key first, to get around a strange iPad
     // issue: http://stackoverflow.com/questions/2603682/is-anyone-else-receiving-a-quota-exceeded-err-on-their-ipad-when-accessing-locals
-    window.localStorage.removeItem("cache");
+    window.localStorage.removeItem(CACHE_NAME);
 
     // TODO: We should really catch QUOTA_EXCEEDED_ERR here,
     // which could be thrown if the user is in private
     // browsing mode.
-    window.localStorage.setItem("cache", JSON.stringify(cache));
+    window.localStorage.setItem(CACHE_NAME, JSON.stringify(cache));
   };
+
   exports.get = function get(key) {
     return cache[key];
   };
+
+  exports.clear = function clear() {
+    window.localStorage.removeItem(CACHE_NAME);
+    cache = {};
+  };
 };