# HG changeset patch # User Atul Varma # Date 1272249079 25200 # Node ID 312d4af344c2e1f48c8944ad6dfdd7933289cb44 # Parent 1a0a3abbba9393b3c5d8f270f1457a20648426ee Fixed cache.js for iPad. diff -r 1a0a3abbba93 -r 312d4af344c2 js/modules/cache.js --- a/js/modules/cache.js Sun Apr 25 18:58:56 2010 -0700 +++ b/js/modules/cache.js Sun Apr 25 19:31:19 2010 -0700 @@ -1,15 +1,23 @@ Require.modules["cache"] = function(exports, require) { var window = require("window"); - var cache; + var cache = window.localStorage.getItem("cache"); - if (window.localStorage["cache"]) { - cache = JSON.parse(window.localStorage["cache"]); - } else + if (cache) + cache = JSON.parse(cache); + else cache = {}; exports.set = function set(key, value) { cache[key] = value; - window.localStorage["cache"] = JSON.stringify(cache); + + // 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"); + + // 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)); }; exports.get = function get(key) { return cache[key];