Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/elemHide.js

Issue 30007559: Issue 7285 - Abstract caching logic (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add tests and change API and behavior slightly Created Feb. 16, 2019, 12:14 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« lib/caching.js ('K') | « lib/caching.js ('k') | lib/matcher.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/elemHide.js
===================================================================
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -19,33 +19,28 @@
/**
* @fileOverview Element hiding implementation.
*/
const {ElemHideExceptions} = require("./elemHideExceptions");
const {filterNotifier} = require("./filterNotifier");
const {normalizeHostname, suffixes} = require("./domain");
+const {Cache} = require("./caching");
/**
* The maximum number of selectors in a CSS rule. This is used by
* <code>{@link createStyleSheet}</code> to split up a long list of selectors
* into multiple rules.
* @const {number}
* @default
*/
const selectorGroupSize = 1024;
/**
- * The maximum number of entries to keep in
- * <code>{@link styleSheetCache}</code>.
- */
-const maxStyleSheetCacheEntries = 100;
-
-/**
* Lookup table, active flag, by filter by domain.
* (Only contains filters that aren't unconditionally matched for all domains.)
* @type {Map.<string,Map.<Filter,boolean>>}
*/
let filtersByDomain = new Map();
/**
* Lookup table, filter by selector. (Only used for selectors that are
@@ -77,19 +72,19 @@
* @type {?string}
*/
let commonStyleSheet = null;
/**
* Cache of generated domain-specific style sheets. This contains entries for
* only known domains. If a domain is unknown, it gets
* <code>{@link commonStyleSheet}</code>.
- * @type {Map.<string,string>}
+ * @type {Cache.<string, string>}
*/
-let styleSheetCache = new Map();
+let styleSheetCache = new Cache(100);
/**
* Map to be used instead when a filter has a blank domains property.
* @type {Map.<string,boolean>}
* @const
*/
let defaultDomains = new Map([["", true]]);
@@ -232,20 +227,16 @@
*/
function getDomainSpecificStyleSheet(domain)
{
let styleSheet = styleSheetCache.get(domain);
if (typeof styleSheet == "undefined")
{
styleSheet = createStyleSheet(getConditionalSelectors(domain, false));
-
- if (styleSheetCache.size >= maxStyleSheetCacheEntries)
- styleSheetCache.clear();
-
styleSheetCache.set(domain, styleSheet);
}
return styleSheet;
}
ElemHideExceptions.on("added", ({domains, selector}) =>
{
« lib/caching.js ('K') | « lib/caching.js ('k') | lib/matcher.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld