diff --git a/lib/cartodb/cache/backend/fastly.js b/lib/cartodb/cache/backend/fastly.js new file mode 100644 index 00000000..91cf162a --- /dev/null +++ b/lib/cartodb/cache/backend/fastly.js @@ -0,0 +1,18 @@ +var FastlyPurge = require('fastly-purge'); + +function FastlyCacheBackend(apiKey, serviceId, softPurge) { + this.serviceId = serviceId; + this.fastlyPurge = new FastlyPurge(apiKey, { softPurge: softPurge || true }); +} + +module.exports = FastlyCacheBackend; + +/** + * @param cacheObject should respond to `key() -> String` method + * @param {Function} callback + */ +FastlyCacheBackend.prototype.invalidate = function(cacheObject, callback) { + this.fastlyPurge.key(this.serviceId, cacheObject.key(), callback); +}; + +module.exports = FastlyCacheBackend;