diff --git a/NEWS.md b/NEWS.md index 9c7e9d99..1d439c47 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 -------------------- diff --git a/config/environments/development.js.example b/config/environments/development.js.example index 22a66806..d684cd7f 100644 --- a/config/environments/development.js.example +++ b/config/environments/development.js.example @@ -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 diff --git a/config/environments/production.js.example b/config/environments/production.js.example index 2a47ea5b..54b85364 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -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 diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index 446d5c2f..23baf426 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -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 diff --git a/config/environments/test.js.example b/config/environments/test.js.example index 9fa7aca8..db807c85 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -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 diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 4ac405dd..adea9a3c 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -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()); diff --git a/test/acceptance/multilayer.js b/test/acceptance/multilayer.js index ed1b1f4c..64066a39 100644 --- a/test/acceptance/multilayer.js +++ b/test/acceptance/multilayer.js @@ -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) {