From 6e7051814697ae8c815ea55cbf56c2f5b4999fc8 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Fri, 23 Jan 2015 17:46:16 +0100 Subject: [PATCH] Split between old cache_enabled and new purge_enabled configuration --- config/environments/development.js.example | 1 + config/environments/production.js.example | 1 + config/environments/staging.js.example | 1 + config/environments/test.js.example | 1 + lib/cartodb/cartodb_windshaft.js | 20 ++++++++++---------- lib/cartodb/server_options.js | 1 + 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config/environments/development.js.example b/config/environments/development.js.example index 24daad9b..e249c479 100644 --- a/config/environments/development.js.example +++ b/config/environments/development.js.example @@ -151,6 +151,7 @@ var config = { host: 'localhost', port: 6082, http_port: 6081, + purge_enabled: false, secret: 'xxx', ttl: 86400, layergroupTtl: 86400 // the max-age for cache-control header in layergroup responses diff --git a/config/environments/production.js.example b/config/environments/production.js.example index 8f36f66a..2b03478a 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -145,6 +145,7 @@ var config = { host: 'localhost', port: 6082, http_port: 6081, + purge_enabled: false, secret: 'xxx', ttl: 86400, layergroupTtl: 86400 // the max-age for cache-control header in layergroup responses diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index f559d2a2..2403f26d 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -145,6 +145,7 @@ var config = { host: 'localhost', port: 6082, http_port: 6081, + purge_enabled: false, secret: 'xxx', ttl: 86400, layergroupTtl: 86400 // the max-age for cache-control header in layergroup responses diff --git a/config/environments/test.js.example b/config/environments/test.js.example index 2c3a8629..1c662c63 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -147,6 +147,7 @@ var config = { host: '', port: null, http_port: 6081, + purge_enabled: false, secret: 'xxx', ttl: 86400, layergroupTtl: 86400 // the max-age for cache-control header in layergroup responses diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 0a42ff06..a43ae965 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -25,6 +25,15 @@ var CartodbWindshaft = function(serverOptions) { var cartoData = require('cartodb-redis')({pool: redisPool}); + if(serverOptions.cache_enabled) { + console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ', serverOptions.varnish_port); + Cache.init(serverOptions.varnish_host, serverOptions.varnish_port, serverOptions.varnish_secret); + serverOptions.afterStateChange = function(req, data, callback) { + Cache.invalidate_db(req.params.dbname, req.params.table); + callback(null, data); + }; + } + serverOptions.beforeStateChange = function(req, callback) { var err = null; if ( ! req.params.hasOwnProperty('_authorizedByApiKey') ) { @@ -51,16 +60,7 @@ var CartodbWindshaft = function(serverOptions) { varnishHttpCacheBackend = new VarnishHttpCacheBackend(serverOptions.varnish_host, serverOptions.varnish_http_port), surrogateKeysCache = new SurrogateKeysCache(varnishHttpCacheBackend); - if (serverOptions.cache_enabled) { - - console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ', serverOptions.varnish_port); - - Cache.init(serverOptions.varnish_host, serverOptions.varnish_port, serverOptions.varnish_secret); - serverOptions.afterStateChange = function(req, data, callback) { - Cache.invalidate_db(req.params.dbname, req.params.table); - callback(null, data); - }; - + if (serverOptions.varnish_purge_enabled) { function invalidateNamedMap(owner, templateName) { surrogateKeysCache.invalidate(new NamedMapsCacheEntry(owner, templateName), function(err) { if (err) { diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 45dcde1a..a731535b 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -91,6 +91,7 @@ module.exports = function(redisPool) { varnish_port: global.environment.varnish.port, varnish_http_port: global.environment.varnish.http_port, varnish_secret: global.environment.varnish.secret, + varnish_purge_enabled: global.environment.varnish.purge_enabled, cache_enabled: global.environment.cache_enabled, log_format: global.environment.log_format, useProfiler: global.environment.useProfiler