1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-21 10:21:35 +02:00

fix broken short-term per-page cache

This commit is contained in:
gorhill 2016-07-01 00:16:10 -04:00
parent 8374799c7d
commit d092f02573

View File

@ -58,13 +58,13 @@ NetFilteringResultCacheEntry.prototype.init = function(result, type) {
this.result = result; this.result = result;
this.type = type; this.type = type;
this.time = Date.now(); this.time = Date.now();
return this;
}; };
/******************************************************************************/ /******************************************************************************/
NetFilteringResultCacheEntry.prototype.dispose = function() { NetFilteringResultCacheEntry.prototype.dispose = function() {
this.result = ''; this.result = this.type = '';
this.type = '';
if ( netFilteringResultCacheEntryJunkyard.length < netFilteringResultCacheEntryJunkyardMax ) { if ( netFilteringResultCacheEntryJunkyard.length < netFilteringResultCacheEntryJunkyardMax ) {
netFilteringResultCacheEntryJunkyard.push(this); netFilteringResultCacheEntryJunkyard.push(this);
} }
@ -73,13 +73,10 @@ NetFilteringResultCacheEntry.prototype.dispose = function() {
/******************************************************************************/ /******************************************************************************/
NetFilteringResultCacheEntry.factory = function(result, type) { NetFilteringResultCacheEntry.factory = function(result, type) {
var entry = netFilteringResultCacheEntryJunkyard.pop(); if ( netFilteringResultCacheEntryJunkyard.length ) {
if ( entry === undefined ) { return netFilteringResultCacheEntryJunkyard.pop().init(result, type);
entry = new NetFilteringResultCacheEntry(result, type);
} else {
entry.init(result, type);
} }
return entry; return new NetFilteringResultCacheEntry(result, type);
}; };
/******************************************************************************/ /******************************************************************************/
@ -110,7 +107,7 @@ NetFilteringResultCache.factory = function() {
/******************************************************************************/ /******************************************************************************/
NetFilteringResultCache.prototype.init = function() { NetFilteringResultCache.prototype.init = function() {
this.urls = {}; this.urls = Object.create(null);
this.count = 0; this.count = 0;
this.shelfLife = 15 * 1000; this.shelfLife = 15 * 1000;
this.timer = null; this.timer = null;
@ -131,16 +128,17 @@ NetFilteringResultCache.prototype.dispose = function() {
/******************************************************************************/ /******************************************************************************/
NetFilteringResultCache.prototype.add = function(context, result) { NetFilteringResultCache.prototype.add = function(context, result) {
var url = context.requestURL; var url = context.requestURL,
var type = context.requestType; type = context.requestType,
var entry = this.urls[url]; key = type + ' ' + url,
entry = this.urls[key];
if ( entry !== undefined ) { if ( entry !== undefined ) {
entry.result = result; entry.result = result;
entry.type = type; entry.type = type;
entry.time = Date.now(); entry.time = Date.now();
return; return;
} }
this.urls[url] = NetFilteringResultCacheEntry.factory(result, type); this.urls[key] = NetFilteringResultCacheEntry.factory(result, type);
if ( this.count === 0 ) { if ( this.count === 0 ) {
this.pruneAsync(); this.pruneAsync();
} }
@ -151,12 +149,9 @@ NetFilteringResultCache.prototype.add = function(context, result) {
NetFilteringResultCache.prototype.empty = function() { NetFilteringResultCache.prototype.empty = function() {
for ( var key in this.urls ) { for ( var key in this.urls ) {
if ( this.urls.hasOwnProperty(key) === false ) {
continue;
}
this.urls[key].dispose(); this.urls[key].dispose();
} }
this.urls = {}; this.urls = Object.create(null);
this.count = 0; this.count = 0;
if ( this.timer !== null ) { if ( this.timer !== null ) {
clearTimeout(this.timer); clearTimeout(this.timer);