diff --git a/lru-cache.js b/lru-cache.js index b68021f..a5cbcad 100644 --- a/lru-cache.js +++ b/lru-cache.js @@ -63,8 +63,8 @@ Cache.prototype = { return Math.max(0, (this.order.length - this.size)); } else if (this.type === typeEnum.heap) { if (getHeapSize() >= this.size) { - // Remove a quarter of them. - return (this.order.length >> 2); + // Remove half of them. + return (this.order.length >> 1); } else { return 0; } } else { console.error("Unknown heuristic for LRU cache."); diff --git a/server.js b/server.js index 5db7e7f..b53c41b 100644 --- a/server.js +++ b/server.js @@ -147,8 +147,8 @@ var minAccuracy = 0.75; // = 1 - max(1, df) / rf var freqRatioMax = 1 - minAccuracy; -// Request cache size of 500MB heap limit. -var requestCache = new LruCache(500000000, 'heap'); +// Request cache size of 400MB heap limit. +var requestCache = new LruCache(400000000, 'heap'); // Deep error handling for vendor hooks. var vendorDomain = domain.create(); @@ -219,11 +219,13 @@ function cache(f) { options = uri; } return request(options, function(err, res, json) { - var cacheControl = res.headers['cache-control']; - if (cacheControl != null) { - var age = cacheControl.match(/max-age=([0-9]+)/); - if ((age != null) && (+age[1] === +age[1])) { - cacheInterval = +age[1] * 1000; + if (res != null && res.headers != null) { + var cacheControl = res.headers['cache-control']; + if (cacheControl != null) { + var age = cacheControl.match(/max-age=([0-9]+)/); + if ((age != null) && (+age[1] === +age[1])) { + cacheInterval = +age[1] * 1000; + } } } callback(err, res, json);