From 37cf676063d07aef9d674f7e99910031b4d13175 Mon Sep 17 00:00:00 2001 From: Simon Tokumine Date: Tue, 6 Dec 2011 01:46:02 +0000 Subject: [PATCH 1/4] set last modified and cache control for varnish --- lib/cartodb/cartodb_windshaft.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 26e84eed..fb424400 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -9,6 +9,8 @@ var CartodbWindshaft = function(serverOptions) { // set the cache chanel info to invalidate the cache on the frontend server serverOptions.afterTileRender = function(req, res, tile, headers, callback) { res.header('X-Cache-Channel', req.params.dbname); + res.header('Last-Modified','Wed, 30 Aug 1978 00:00:00 GMT'); // special date in the past. + res.header('Cache-Control','no-cache,must-revalidate, public'); callback(null, tile, headers); }; From 74cd176eb54ff79b03680fbf8f2d1e8714f051d0 Mon Sep 17 00:00:00 2001 From: Simon Tokumine Date: Tue, 6 Dec 2011 16:32:23 +0000 Subject: [PATCH 2/4] reconnect if varnish is down --- lib/cartodb/cartodb_windshaft.js | 5 +++-- lib/cartodb/varnish.js | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index fb424400..2c7820b0 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -9,8 +9,9 @@ var CartodbWindshaft = function(serverOptions) { // set the cache chanel info to invalidate the cache on the frontend server serverOptions.afterTileRender = function(req, res, tile, headers, callback) { res.header('X-Cache-Channel', req.params.dbname); - res.header('Last-Modified','Wed, 30 Aug 1978 00:00:00 GMT'); // special date in the past. - res.header('Cache-Control','no-cache,must-revalidate, public'); +// note - not invalidating properly +// res.header('Last-Modified','Wed, 30 Aug 1978 00:00:00 GMT'); // special date in the past. +// res.header('Cache-Control','no-cache,must-revalidate, public'); callback(null, tile, headers); }; diff --git a/lib/cartodb/varnish.js b/lib/cartodb/varnish.js index 977f5bdc..89f67e5f 100644 --- a/lib/cartodb/varnish.js +++ b/lib/cartodb/varnish.js @@ -51,7 +51,15 @@ function VarnishClient(host, port, ready_callback) { // sends the command to the server function _send(cmd, callback) { cmd_callback = callback; - client.write(cmd + '\n'); + + // If varnish down attempt simple reconnect + try{ + client.write(cmd + '\n'); + } catch(err) { + self.close(); + connect(); + client.write(cmd + '\n'); + } } // run command if there is no peding response From 6d05c8363158b2701701bc629ff66ff9b9512795 Mon Sep 17 00:00:00 2001 From: Simon Tokumine Date: Tue, 6 Dec 2011 16:39:21 +0000 Subject: [PATCH 3/4] add readycallback to reconnect --- lib/cartodb/varnish.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/cartodb/varnish.js b/lib/cartodb/varnish.js index 89f67e5f..d621e45d 100644 --- a/lib/cartodb/varnish.js +++ b/lib/cartodb/varnish.js @@ -58,6 +58,8 @@ function VarnishClient(host, port, ready_callback) { } catch(err) { self.close(); connect(); + ready=true; + ready_callback(); client.write(cmd + '\n'); } } From 473a2d55a5037b49a523c2245d1589d9778593bb Mon Sep 17 00:00:00 2001 From: Simon Tokumine Date: Tue, 6 Dec 2011 17:13:56 +0000 Subject: [PATCH 4/4] reinstate 304 --- lib/cartodb/cartodb_windshaft.js | 6 +++--- lib/cartodb/varnish.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 2c7820b0..f450240a 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -9,9 +9,9 @@ var CartodbWindshaft = function(serverOptions) { // set the cache chanel info to invalidate the cache on the frontend server serverOptions.afterTileRender = function(req, res, tile, headers, callback) { res.header('X-Cache-Channel', req.params.dbname); -// note - not invalidating properly -// res.header('Last-Modified','Wed, 30 Aug 1978 00:00:00 GMT'); // special date in the past. -// res.header('Cache-Control','no-cache,must-revalidate, public'); + // note - may not be invalidating properly + res.header('Last-Modified', new Date().toUTCString()); + res.header('Cache-Control', 'no-cache,must-revalidate, public'); callback(null, tile, headers); }; diff --git a/lib/cartodb/varnish.js b/lib/cartodb/varnish.js index d621e45d..80784364 100644 --- a/lib/cartodb/varnish.js +++ b/lib/cartodb/varnish.js @@ -20,7 +20,7 @@ function VarnishClient(host, port, ready_callback) { connect(); - client.on('data', function(data) { + client.on('data', function (data) { data = data.toString(); lines = data.split('\n', 2); if(lines.length == 2) {