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}) => |
{ |