2015-03-16 07:16:36 +08:00
|
|
|
var Varnish = require('node-varnish');
|
|
|
|
var varnish_queue = null;
|
2011-10-13 19:17:00 +08:00
|
|
|
|
2014-02-12 22:34:19 +08:00
|
|
|
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);
|
|
|
|
});
|
2011-12-01 02:59:28 +08:00
|
|
|
}
|
2011-10-13 19:17:00 +08:00
|
|
|
|
2012-05-03 02:32:54 +08:00
|
|
|
function invalidate_db(dbname, table) {
|
2014-02-12 22:34:19 +08:00
|
|
|
var cmd = 'purge obj.http.X-Cache-Channel ~ "^' + dbname +
|
|
|
|
':(.*'+ table +'.*)|(table)$"';
|
2012-05-03 02:32:54 +08:00
|
|
|
try{
|
2014-02-12 22:34:19 +08:00
|
|
|
varnish_queue.run_cmd(cmd, false);
|
2012-05-03 02:32:54 +08:00
|
|
|
} catch (e) {
|
2014-02-12 22:34:19 +08:00
|
|
|
console.log("[CACHE VALIDATOR ERROR] could not queue command " +
|
|
|
|
cmd + " -- " + e);
|
2012-05-03 02:32:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-01 02:59:28 +08:00
|
|
|
module.exports = {
|
|
|
|
init: init,
|
2013-03-13 23:45:15 +08:00
|
|
|
invalidate_db: invalidate_db
|
2015-03-16 06:46:59 +08:00
|
|
|
};
|