2012-05-03 02:32:54 +08:00
var _ = require ( 'underscore' ) ,
Varnish = require ( 'node-varnish' ) ,
varnish _queue = null ;
2011-10-13 19:17:00 +08:00
2011-12-01 02:59:28 +08:00
function init ( host , port ) {
varnish _queue = new Varnish . VarnishQueue ( host , port ) ;
}
2011-10-13 19:17:00 +08:00
2012-05-03 02:32:54 +08:00
function invalidate _db ( dbname , table ) {
try {
varnish _queue . run _cmd ( 'purge obj.http.X-Cache-Channel ~ "^' + dbname + ':(.*' + table + '.*)|(table)$"' ) ;
console . log ( '[SUCCESS FLUSHING CACHE]' ) ;
} catch ( e ) {
console . log ( "[ERROR FLUSHING CACHE] Is enable_cache set to true? Failed for: " + 'purge obj.http.X-Cache-Channel ~ "^' + dbname + ':(.*' + table + '.*)|(table)$"' ) ;
}
}
2011-12-01 02:59:28 +08:00
module . exports = {
init : init ,
2013-03-13 23:45:15 +08:00
invalidate _db : invalidate _db
2011-10-13 19:17:00 +08:00
}