ttl options and tests
This commit is contained in:
@@ -8,7 +8,9 @@ var CartodbWindshaft = function(serverOptions) {
|
||||
|
||||
// set cache if requested
|
||||
if(serverOptions.lru_cache) {
|
||||
var lru_cache = Cache.LRUcache(serverOptions.lru_cache_size || 10000, serverOptions.redis);
|
||||
var lru_cache = Cache.LRUcache(serverOptions.lru_cache_size || 10000,
|
||||
serverOptions.redis,
|
||||
serverOptions.ttl_timeout);
|
||||
_.extend(serverOptions, {
|
||||
beforeTileRender: lru_cache.beforeTileRender,
|
||||
afterTileRender: lru_cache.afterTileRender,
|
||||
|
||||
@@ -25,9 +25,9 @@ module.exports.NoCache = function() {
|
||||
|
||||
}
|
||||
|
||||
module.exports.LRUcache = function(max_items, redis_opts) {
|
||||
module.exports.LRUcache = function(max_items, redis_opts, ttl_timeout) {
|
||||
var cache_validator = CacheValidator(redis_opts);
|
||||
return GenericCache(new LRUCache(max_items), cache_validator);
|
||||
return GenericCache(new LRUCache(max_items), cache_validator, ttl_timeout || 600);
|
||||
}
|
||||
|
||||
// implements a generic cache for tile
|
||||
@@ -161,6 +161,7 @@ function GenericCache (cache_policy, cache_validator, ttl_timeout) {
|
||||
cache_invalidated: me.cache_invalidated,
|
||||
cache_not_modified: me.cache_not_modified,
|
||||
current_items: me.current_items,
|
||||
expired: me.expired,
|
||||
max_items: me.max_items,
|
||||
memory: mem,
|
||||
memory_per_item: total ? mem/total: 0,
|
||||
|
||||
@@ -130,7 +130,6 @@ tests["cache should be invalidated"] = function() {
|
||||
},{
|
||||
status: 200
|
||||
}, function(r) {
|
||||
console.log('hiy', r.header('X-Cache-hit'));
|
||||
assert.ok(r.header('X-Cache-hit') === undefined);
|
||||
});
|
||||
});
|
||||
@@ -171,3 +170,45 @@ tests["Last-Modified header should be sent"] = function() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
tests["TTL should invalidate a tile"] = function() {
|
||||
|
||||
var url = '/tiles/test_table_2/6/31/24.png';
|
||||
|
||||
//create another server to not take previos test stats into account
|
||||
var so = _.clone(serverOptions);
|
||||
_(so).extend({ttl_timeout: 1});
|
||||
|
||||
var _cached_server = new CartodbWindshaft(so);
|
||||
// cache it
|
||||
assert.response(_cached_server, {
|
||||
url: url,
|
||||
headers: {host: 'vizzuality.localhost.lan'},
|
||||
method: 'GET'
|
||||
},{
|
||||
status: 200
|
||||
}, function(res) {
|
||||
console.log("WAIT A LITTLE BIT PLEASE");
|
||||
|
||||
// test before invalidating
|
||||
setTimeout(function() {
|
||||
var st = so.cacheStats();
|
||||
assert.eql(st.expired, 0);
|
||||
}, 500);
|
||||
|
||||
// test after invalidation
|
||||
setTimeout(function() {
|
||||
assert.response(_cached_server, {
|
||||
url: url,
|
||||
headers: {host: 'vizzuality.localhost.lan'},
|
||||
method: 'GET'
|
||||
},{
|
||||
status: 200
|
||||
}, function(res) {
|
||||
assert.ok(res.header('X-Cache-hit') === undefined);
|
||||
var st = so.cacheStats();
|
||||
assert.eql(st.expired, 1);
|
||||
});
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user