Expose Varnish cache TTL in configuration. Closes #46

This commit is contained in:
Sandro Santilli 2012-09-03 18:57:35 +02:00
parent c23f136f04
commit 87b0e07815
4 changed files with 8 additions and 4 deletions

View File

@ -32,7 +32,8 @@ var config = {
} }
,varnish: { ,varnish: {
host: 'localhost', host: 'localhost',
port: 6082 port: 6082,
ttl: 86400
} }
}; };

View File

@ -24,7 +24,8 @@ var config = {
} }
,varnish: { ,varnish: {
host: 'localhost', host: 'localhost',
port: 6082 port: 6082,
ttl: 86400
} }
}; };

View File

@ -27,7 +27,8 @@ var config = {
} }
,varnish: { ,varnish: {
host: '', host: '',
port: null port: null,
ttl: 86400
} }
}; };

View File

@ -8,10 +8,11 @@ var CartodbWindshaft = function(serverOptions) {
// set the cache chanel info to invalidate the cache on the frontend server // set the cache chanel info to invalidate the cache on the frontend server
serverOptions.afterTileRender = function(req, res, tile, headers, callback) { serverOptions.afterTileRender = function(req, res, tile, headers, callback) {
var ttl = global.environment.varnish.ttl || 86400;
Cache.generateCacheChannel(req, function(channel){ Cache.generateCacheChannel(req, function(channel){
res.header('X-Cache-Channel', channel); res.header('X-Cache-Channel', channel);
res.header('Last-Modified', new Date().toUTCString()); res.header('Last-Modified', new Date().toUTCString());
res.header('Cache-Control', 'no-cache,max-age=86400,must-revalidate, public'); res.header('Cache-Control', 'no-cache,max-age='+ttl+',must-revalidate, public');
callback(null, tile, headers); callback(null, tile, headers);
}); });
}; };