@ -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 ) ;
}
}