Do not send multiple equal commands to Varnish on connect

Closes #135
Also accept varnish "secret" in config
remotes/origin/use_db_slaves
Sandro Santilli 11 years ago
parent cdbcc7dc18
commit bf45bbea56

@ -5,6 +5,8 @@ Enhancements:
* Add script to flush caches (#140)
* Add statsd support (#139)
* Add support for specifying a varnish password
* Avoid sending multiple varnish invalidation at once (#135)
1.7.1 -- 2014-02-11
-------------------

@ -99,6 +99,7 @@ var config = {
,varnish: {
host: 'localhost',
port: 6082,
secret: 'xxx',
ttl: 86400
}
// If useProfiler is true every response will be served with an

@ -93,6 +93,7 @@ var config = {
,varnish: {
host: 'localhost',
port: 6082,
secret: 'xxx',
ttl: 86400
}
// If useProfiler is true every response will be served with an

@ -93,6 +93,7 @@ var config = {
,varnish: {
host: 'localhost',
port: 6082,
secret: 'xxx',
ttl: 86400
}
// If useProfiler is true every response will be served with an

@ -95,6 +95,7 @@ var config = {
,varnish: {
host: '',
port: null,
secret: 'xxx',
ttl: 86400
}
// If useProfiler is true every response will be served with an

@ -2,16 +2,21 @@ var _ = require('underscore'),
Varnish = require('node-varnish'),
varnish_queue = null;
function init(host, port) {
varnish_queue = new Varnish.VarnishQueue(host, port);
function init(host, port, secret) {
varnish_queue = new Varnish.VarnishQueue(host, port, secret);
varnish_queue.on('error', function(e) {
console.log("[CACHE VALIDATOR ERROR] " + e);
});
}
function invalidate_db(dbname, table) {
var cmd = 'purge obj.http.X-Cache-Channel ~ "^' + dbname +
':(.*'+ table +'.*)|(table)$"';
try{
varnish_queue.run_cmd('purge obj.http.X-Cache-Channel ~ "^' + dbname + ':(.*'+ table +'.*)|(table)$"');
console.log('[SUCCESS FLUSHING CACHE]');
varnish_queue.run_cmd(cmd, false);
} catch (e) {
console.log("[ERROR FLUSHING CACHE] Is enable_cache set to true? Failed for: " + 'purge obj.http.X-Cache-Channel ~ "^' + dbname + ':(.*'+ table +'.*)|(table)$"');
console.log("[CACHE VALIDATOR ERROR] could not queue command " +
cmd + " -- " + e);
}
}

@ -14,7 +14,7 @@ var CartodbWindshaft = function(serverOptions) {
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);
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);

@ -62,6 +62,7 @@ module.exports = function(){
enable_cors: global.environment.enable_cors,
varnish_host: global.environment.varnish.host,
varnish_port: global.environment.varnish.port,
varnish_secret: global.environment.varnish.secret,
cache_enabled: global.environment.cache_enabled,
log_format: global.environment.log_format,
useProfiler: global.environment.useProfiler

@ -3,7 +3,8 @@
"version": "1.7.1",
"dependencies": {
"node-varnish": {
"version": "0.1.1"
"version": "0.2.0",
"from": "http://github.com/Vizzuality/node-varnish/tarball/v0.2.0"
},
"underscore": {
"version": "1.3.3"

@ -22,7 +22,7 @@
"Sandro Santilli <strk@vizzuality.com>"
],
"dependencies": {
"node-varnish": "0.1.1",
"node-varnish": "0.2.0",
"underscore" : "~1.3.3",
"windshaft" : "~0.17.2",
"step": "0.0.x",

Loading…
Cancel
Save