From 46e93355c4b49197eeb423936030c1b99c5e5bae Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 28 Jun 2013 11:15:34 +0200 Subject: [PATCH] Set max-age=0 when using no-cache (don't be self-contraddicting) --- NEWS.md | 1 + app/controllers/app.js | 9 ++++++--- test/acceptance/app.test.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2d1bdae4..68244475 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * Add --skipfields switch to cdbsql * Fix windowing with CTE * Retain UTC offset in JSON date output +* Set max-age=0 in Cache-Control when using no-cache 1.4.0 ----- diff --git a/app/controllers/app.js b/app/controllers/app.js index 2daa9612..cd438aa1 100755 --- a/app/controllers/app.js +++ b/app/controllers/app.js @@ -262,10 +262,13 @@ function handleQuery(req, res) { if ( cache_policy == 'persist' ) { res.header('Cache-Control', 'public,max-age=31536000'); // 1 year } else { - // TODO: set ttl=0 when tableCache[sql_md5].may_write is true ? - var ttl = 3600; + // don't cache the result ! + // NOTE: both Varnish and Cloudfront ignore this header, + // X-Cache-Channel is for controlling Varnish + // Cloudfront can only be skipped perturbating the URL + // res.header('Last-Modified', new Date().toUTCString()); - res.header('Cache-Control', 'no-cache,max-age='+ttl+',must-revalidate,public'); + res.header('Cache-Control', 'no-cache,max-age=0,must-revalidate,public'); } return result; diff --git a/test/acceptance/app.test.js b/test/acceptance/app.test.js index e749742c..9c77ba4b 100644 --- a/test/acceptance/app.test.js +++ b/test/acceptance/app.test.js @@ -30,7 +30,7 @@ app.setMaxListeners(0); suite('app.test', function() { -var expected_cache_control = 'no-cache,max-age=3600,must-revalidate,public'; +var expected_cache_control = 'no-cache,max-age=0,must-revalidate,public'; var expected_cache_control_persist = 'public,max-age=31536000'; test('GET /api/v1/sql', function(done){