From b014fda4a2837e2717592d7b690c9b020762999f Mon Sep 17 00:00:00 2001 From: Kerrick Long Date: Sun, 29 Apr 2012 08:35:01 -0500 Subject: [PATCH] fixes #25; changed Background.clearCache() from a nuke to a machine gun. --- js/common.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/js/common.js b/js/common.js index 10bb8fe..d155328 100644 --- a/js/common.js +++ b/js/common.js @@ -961,12 +961,22 @@ function Background() { * @method */ Background.prototype.clearCache = function () { - var oldReddits; + var oldCache, newCache; - oldReddits = cache.get('reddits'); - cache.removeAll(); - button.setBadgeDefaults(); - cache.set('reddits', oldReddits) + oldCache = cache.toObject(); + newCache = { + modhash: oldCache.modhash, + reddits: oldCache.reddits + }; + + utils.forEachIn(oldCache, function (cachedUrl, data) { + chrome.tabs.query({url: cachedUrl}, function (results) { + if (results.length > 0) { + newCache[cachedUrl] = oldCache[cachedUrl]; + } + cache.fromObject(newCache); // It's messy to put it here since it'll get called over and over, but chrome.tabs.query is asynch. + }); + }); }; /**