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
* {@link createStyleSheet}
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
- * {@link styleSheetCache}
.
- */
-const maxStyleSheetCacheEntries = 100;
-
-/**
* Lookup table, active flag, by filter by domain.
* (Only contains filters that aren't unconditionally matched for all domains.)
* @type {Map.>}
*/
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
* {@link commonStyleSheet}
.
- * @type {Map.}
+ * @type {Cache.}
*/
-let styleSheetCache = new Map();
+let styleSheetCache = new Cache(100);
/**
* Map to be used instead when a filter has a blank domains property.
* @type {Map.}
* @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}) =>
{