diff --git a/lib/ActivityStreams.js b/lib/ActivityStreams.js index f66d31464a..4214445733 100644 --- a/lib/ActivityStreams.js +++ b/lib/ActivityStreams.js @@ -187,7 +187,6 @@ ActivityStreams.prototype = { /* note: this will execute for each of the 3 notifications that occur * when adding a visit: frecency:-1, frecency: real frecency, title */ if (!this._populatingCache.places) { - this._invalidatePlacesCache(); this._asyncBuildPlacesCache(); } @@ -300,13 +299,14 @@ ActivityStreams.prototype = { if (simplePrefs.prefs["query.cache"]) { if (!this._populatingCache.places) { this._populatingCache.places = true; + let opt = {replace: true}; yield Promise.all([ - this._memoized.getTopFrecentSites(), - this._memoized.getRecentBookmarks(), - this._memoized.getRecentLinks(), - this._memoized.getHighlightsLinks(), - this._memoized.getHistorySize(), - this._memoized.getBookmarksSize(), + this._memoized.getTopFrecentSites(opt), + this._memoized.getRecentBookmarks(opt), + this._memoized.getRecentLinks(opt), + this._memoized.getHighlightsLinks(opt), + this._memoized.getHistorySize(opt), + this._memoized.getBookmarksSize(opt), ]); this._populatingCache.places = false; Services.obs.notifyObservers(null, "activity-streams-places-cache-complete", null); @@ -360,20 +360,6 @@ ActivityStreams.prototype = { } }, - /** - * Invalidates the places pageload cache - */ - _invalidatePlacesCache() { - this._memoizer.invalidateMemos([ - "getTopFrecentSites", - "getRecentBookmarks", - "getRecentLinks", - "getHighlightsLinks", - "getHistorySize", - "getBookmarksSize", - ]); - }, - /** * Sets up communications with the pages and manages the lifecycle of workers */ diff --git a/lib/Memoizer.js b/lib/Memoizer.js index ba73e94ced..1bcb9610b6 100644 --- a/lib/Memoizer.js +++ b/lib/Memoizer.js @@ -35,10 +35,21 @@ Memoizer.prototype = { */ memoize(key, func) { return (...args) => { + + // figure out if we need to replace the cache for this query + let replace = false; + args = args.filter(arg => { + if (typeof arg === "object" && "replace" in arg) { + replace = arg.replace; + return false; + } + return true; + }); + // allow object params to be passed, as is expected of query functions let repr = this._makeRepr(args); - if (this._cacheEnabled && this.hasRepr(key, repr)) { + if (this._cacheEnabled && !replace && this.hasRepr(key, repr)) { Services.obs.notifyObservers(null, `${key}-cache`, "hit"); return new Promise(resolve => resolve(this.getData(key, repr))); } else { diff --git a/test/test-Memoizer.js b/test/test-Memoizer.js index 9e426c0432..d3b0af2c73 100644 --- a/test/test-Memoizer.js +++ b/test/test-Memoizer.js @@ -29,6 +29,48 @@ exports.test_memoizer = function*(assert) { assert.equal(result, 2, "cached result is obtained"); }; +exports.test_memoizer_replace_opt = function*(assert) { + let count = 0; + let testFunc = () => { + return ++count; + }; + let func = gMemoizer.memoize("testKey", testFunc); + let result; + + result = yield func(); + assert.equal(result, 1, "test function executes"); + + result = yield func(); + assert.equal(result, 1, "cached result is obtained"); + + result = yield func({replace: true}); + assert.equal(result, 2, "test function executes"); + + result = yield func(); + assert.equal(result, 2, "cached result is obtained"); +}; + +exports.test_memoizer_replace_opt_sub_key = function*(assert) { + let count = 0; + let testFunc = () => { + return ++count; + }; + let func = gMemoizer.memoize("testKey", testFunc); + let result; + + result = yield func("sub-key"); + assert.equal(result, 1, "test function executes"); + + result = yield func("sub-key"); + assert.equal(result, 1, "cached result is obtained"); + + result = yield func("sub-key", {replace: true}); + assert.equal(result, 2, "test function executes"); + + result = yield func("sub-key"); + assert.equal(result, 2, "cached result is obtained"); +}; + exports.test_memoizer_prefs = function*(assert) { simplePrefs.prefs["query.cache"] = false; let count = 0;