faster cache purge

This commit is contained in:
Matias Alejo Garcia 2016-03-01 18:45:42 -03:00
parent 7b0dfeccbc
commit 873fee2fb3
2 changed files with 7 additions and 4 deletions

View File

@ -11,6 +11,7 @@ var async = require('async');
var MAX_BATCH_SIZE = 100;
var RPC_CONCURRENCY = 5;
var SIZE_TO_ENABLE_DEAD_CACHE = 500;
var tDb = require('../../lib/TransactionDb').default();

View File

@ -13,9 +13,8 @@ var TransactionDb = imports.TransactionDb || require('../../lib/TransactionDb').
var BlockDb = imports.BlockDb || require('../../lib/BlockDb').default();
var config = require('../../config/config');
var CONCURRENCY = 5;
//var DAYS_TO_DEAD = 40;
var DAYS_TO_DEAD = 1;
var MAX_CACHE_KEYS = 100;
var DAYS_TO_DEAD = 40;
var MAX_CACHE_KEYS = 10000;
var deadCache = {};
@ -108,10 +107,13 @@ Address.prototype.setCache = function() {
if (size > MAX_CACHE_KEYS) {
console.log('%%%%%%%% deleting ~ 20% of the entries...');
var skip = _.random(4), i=0;
for (var prop in deadCache)
if (Math.random() < 0.2)
if ( !( skip++ % 5 ) )
delete deadCache[prop];
size = _.keys(deadCache).length;
console.log('%%%%%%%% cache size:', size); //TODO
}
// TODO expire it...