Do not send multiple equal commands to Varnish on connect
Closes #135 Also accept varnish "secret" in config
This commit is contained in:
parent
cdbcc7dc18
commit
bf45bbea56
2
NEWS.md
2
NEWS.md
@ -5,6 +5,8 @@ Enhancements:
|
|||||||
|
|
||||||
* Add script to flush caches (#140)
|
* Add script to flush caches (#140)
|
||||||
* Add statsd support (#139)
|
* 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
|
1.7.1 -- 2014-02-11
|
||||||
-------------------
|
-------------------
|
||||||
|
@ -99,6 +99,7 @@ var config = {
|
|||||||
,varnish: {
|
,varnish: {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 6082,
|
port: 6082,
|
||||||
|
secret: 'xxx',
|
||||||
ttl: 86400
|
ttl: 86400
|
||||||
}
|
}
|
||||||
// If useProfiler is true every response will be served with an
|
// If useProfiler is true every response will be served with an
|
||||||
|
@ -93,6 +93,7 @@ var config = {
|
|||||||
,varnish: {
|
,varnish: {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 6082,
|
port: 6082,
|
||||||
|
secret: 'xxx',
|
||||||
ttl: 86400
|
ttl: 86400
|
||||||
}
|
}
|
||||||
// If useProfiler is true every response will be served with an
|
// If useProfiler is true every response will be served with an
|
||||||
|
@ -93,6 +93,7 @@ var config = {
|
|||||||
,varnish: {
|
,varnish: {
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: 6082,
|
port: 6082,
|
||||||
|
secret: 'xxx',
|
||||||
ttl: 86400
|
ttl: 86400
|
||||||
}
|
}
|
||||||
// If useProfiler is true every response will be served with an
|
// If useProfiler is true every response will be served with an
|
||||||
|
@ -95,6 +95,7 @@ var config = {
|
|||||||
,varnish: {
|
,varnish: {
|
||||||
host: '',
|
host: '',
|
||||||
port: null,
|
port: null,
|
||||||
|
secret: 'xxx',
|
||||||
ttl: 86400
|
ttl: 86400
|
||||||
}
|
}
|
||||||
// If useProfiler is true every response will be served with an
|
// If useProfiler is true every response will be served with an
|
||||||
|
@ -2,16 +2,21 @@ var _ = require('underscore'),
|
|||||||
Varnish = require('node-varnish'),
|
Varnish = require('node-varnish'),
|
||||||
varnish_queue = null;
|
varnish_queue = null;
|
||||||
|
|
||||||
function init(host, port) {
|
function init(host, port, secret) {
|
||||||
varnish_queue = new Varnish.VarnishQueue(host, port);
|
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) {
|
function invalidate_db(dbname, table) {
|
||||||
|
var cmd = 'purge obj.http.X-Cache-Channel ~ "^' + dbname +
|
||||||
|
':(.*'+ table +'.*)|(table)$"';
|
||||||
try{
|
try{
|
||||||
varnish_queue.run_cmd('purge obj.http.X-Cache-Channel ~ "^' + dbname + ':(.*'+ table +'.*)|(table)$"');
|
varnish_queue.run_cmd(cmd, false);
|
||||||
console.log('[SUCCESS FLUSHING CACHE]');
|
|
||||||
} catch (e) {
|
} 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) {
|
if(serverOptions.cache_enabled) {
|
||||||
console.log("cache invalidation enabled, varnish on ", serverOptions.varnish_host, ' ', serverOptions.varnish_port);
|
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) {
|
serverOptions.afterStateChange = function(req, data, callback) {
|
||||||
Cache.invalidate_db(req.params.dbname, req.params.table);
|
Cache.invalidate_db(req.params.dbname, req.params.table);
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
|
@ -62,6 +62,7 @@ module.exports = function(){
|
|||||||
enable_cors: global.environment.enable_cors,
|
enable_cors: global.environment.enable_cors,
|
||||||
varnish_host: global.environment.varnish.host,
|
varnish_host: global.environment.varnish.host,
|
||||||
varnish_port: global.environment.varnish.port,
|
varnish_port: global.environment.varnish.port,
|
||||||
|
varnish_secret: global.environment.varnish.secret,
|
||||||
cache_enabled: global.environment.cache_enabled,
|
cache_enabled: global.environment.cache_enabled,
|
||||||
log_format: global.environment.log_format,
|
log_format: global.environment.log_format,
|
||||||
useProfiler: global.environment.useProfiler
|
useProfiler: global.environment.useProfiler
|
||||||
|
3
npm-shrinkwrap.json
generated
3
npm-shrinkwrap.json
generated
@ -3,7 +3,8 @@
|
|||||||
"version": "1.7.1",
|
"version": "1.7.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-varnish": {
|
"node-varnish": {
|
||||||
"version": "0.1.1"
|
"version": "0.2.0",
|
||||||
|
"from": "http://github.com/Vizzuality/node-varnish/tarball/v0.2.0"
|
||||||
},
|
},
|
||||||
"underscore": {
|
"underscore": {
|
||||||
"version": "1.3.3"
|
"version": "1.3.3"
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
"Sandro Santilli <strk@vizzuality.com>"
|
"Sandro Santilli <strk@vizzuality.com>"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"node-varnish": "0.1.1",
|
"node-varnish": "0.2.0",
|
||||||
"underscore" : "~1.3.3",
|
"underscore" : "~1.3.3",
|
||||||
"windshaft" : "~0.17.2",
|
"windshaft" : "~0.17.2",
|
||||||
"step": "0.0.x",
|
"step": "0.0.x",
|
||||||
|
Loading…
Reference in New Issue
Block a user