Windshaft-cartodb/lib/cartodb/cache_validator.js

22 lines
682 B
JavaScript
Raw Normal View History

var _ = require('underscore'),
Varnish = require('node-varnish'),
varnish_queue = null;
2011-12-01 02:59:28 +08:00
function init(host, port) {
varnish_queue = new Varnish.VarnishQueue(host, port);
}
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,
invalidate_db: invalidate_db
}