Allow a different cache-control max-age for layergroup responses

This commit is contained in:
Raul Ochoa 2014-10-24 16:05:41 +02:00
parent ff4ec19fff
commit c88330f5f2
7 changed files with 55 additions and 5 deletions

View File

@ -1,6 +1,9 @@
1.20.3 -- 2014-mm-dd
--------------------
New features:
- Allow a different cache-control max-age for layergroup responses
1.20.2 -- 2014-10-20
--------------------

View File

@ -143,7 +143,8 @@ var config = {
host: 'localhost',
port: 6082,
secret: 'xxx',
ttl: 86400
ttl: 86400,
layergroupTtl: 86400 // the max-age for cache-control header in layergroup responses
}
// If useProfiler is true every response will be served with an
// X-Tiler-Profile header containing elapsed timing for various

View File

@ -137,7 +137,8 @@ var config = {
host: 'localhost',
port: 6082,
secret: 'xxx',
ttl: 86400
ttl: 86400,
layergroupTtl: 86400 // the max-age for cache-control header in layergroup responses
}
// If useProfiler is true every response will be served with an
// X-Tiler-Profile header containing elapsed timing for various

View File

@ -137,7 +137,8 @@ var config = {
host: 'localhost',
port: 6082,
secret: 'xxx',
ttl: 86400
ttl: 86400,
layergroupTtl: 86400 // the max-age for cache-control header in layergroup responses
}
// If useProfiler is true every response will be served with an
// X-Tiler-Profile header containing elapsed timing for various

View File

@ -139,7 +139,8 @@ var config = {
host: '',
port: null,
secret: 'xxx',
ttl: 86400
ttl: 86400,
layergroupTtl: 86400 // the max-age for cache-control header in layergroup responses
}
// If useProfiler is true every response will be served with an
// X-Tiler-Profile header containing elapsed timing for various

View File

@ -342,7 +342,7 @@ module.exports = function(redisPool) {
if ( req.query && req.query.cache_policy == 'persist' ) {
res.header('Cache-Control', 'public,max-age=31536000'); // 1 year
} else {
var ttl = global.environment.varnish.ttl || 86400;
var ttl = global.environment.varnish.layergroupTtl || 86400;
res.header('Cache-Control', 'public,max-age='+ttl+',must-revalidate');
}
res.header('Last-Modified', (new Date()).toUTCString());

View File

@ -1324,6 +1324,49 @@ suite('multilayer:postgres=' + cdbQueryTablesFromPostgresEnabledValue, function(
);
});
var layergroupTtlRequest = {
url: '/tiles/layergroup?config=' + encodeURIComponent(JSON.stringify({
version: '1.0.0',
layers: [
{ options: {
sql: 'select * from test_table limit 2',
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
cartocss_version: '2.0.1'
} }
]
})),
method: 'GET',
headers: {host: 'localhost'}
};
var layergroupTtlResponseExpectation = {
status: 200
};
test("cache control for layergroup default value", function(done) {
global.environment.varnish.layergroupTtl = null;
assert.response(server, layergroupTtlRequest, layergroupTtlResponseExpectation,
function(res) {
assert.equal(res.headers['cache-control'], 'public,max-age=86400,must-revalidate');
done();
}
);
});
test("cache control for layergroup uses configuration for max-age", function(done) {
var layergroupTtl = 300;
global.environment.varnish.layergroupTtl = layergroupTtl;
assert.response(server, layergroupTtlRequest, layergroupTtlResponseExpectation,
function(res) {
assert.equal(res.headers['cache-control'], 'public,max-age=' + layergroupTtl + ',must-revalidate');
done();
}
);
});
suiteTeardown(function(done) {