2018-10-23 23:45:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
2015-04-27 22:18:50 +08:00
|
|
|
var FastlyPurge = require('fastly-purge');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function FastlyCacheBackend (apiKey, serviceId) {
|
2015-04-27 22:18:50 +08:00
|
|
|
this.serviceId = serviceId;
|
2015-10-09 22:37:17 +08:00
|
|
|
this.fastlyPurge = new FastlyPurge(apiKey, { softPurge: false });
|
2015-04-27 22:18:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = FastlyCacheBackend;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param cacheObject should respond to `key() -> String` method
|
|
|
|
* @param {Function} callback
|
|
|
|
*/
|
2019-10-22 01:07:24 +08:00
|
|
|
FastlyCacheBackend.prototype.invalidate = function (cacheObject, callback) {
|
2015-04-27 22:18:50 +08:00
|
|
|
this.fastlyPurge.key(this.serviceId, cacheObject.key(), callback);
|
|
|
|
};
|