From a5b9ca706cbde7a981b89f9cf02ce6d50da8f6f3 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Mon, 27 Apr 2015 16:18:50 +0200 Subject: [PATCH] Adds new fastly cache backend --- lib/cartodb/cache/backend/fastly.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/cartodb/cache/backend/fastly.js 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;