Adds Fastly cache backend

This commit is contained in:
Raul Ochoa 2015-04-27 16:31:47 +02:00
parent 8e8ab09bec
commit 9edec8ef3f

View File

@ -4,6 +4,11 @@ var Windshaft = require('windshaft');
var os = require('os');
var HealthCheck = require('./monitoring/health_check');
var SurrogateKeysCache = require('./cache/surrogate_keys_cache');
var NamedMapsCacheEntry = require('./cache/model/named_maps_entry');
var VarnishHttpCacheBackend = require('./cache/backend/varnish_http');
var FastlyCacheBackend = require('./cache/backend/fastly');
if ( ! process.env.PGAPPNAME )
process.env.PGAPPNAME='cartodb_tiler';
@ -30,14 +35,21 @@ var CartodbWindshaft = function(serverOptions) {
//
var template_baseurl = global.environment.base_url_templated || '(?:/maps/named|/tiles/template)';
var SurrogateKeysCache = require('./cache/surrogate_keys_cache'),
NamedMapsCacheEntry = require('./cache/model/named_maps_entry'),
VarnishHttpCacheBackend = require('./cache/backend/varnish_http'),
varnishHttpCacheBackend = new VarnishHttpCacheBackend(
serverOptions.varnish_host,
serverOptions.varnish_http_port
),
surrogateKeysCache = new SurrogateKeysCache(varnishHttpCacheBackend);
var surrogateKeysCacheBackends = [];
if (serverOptions.varnish_purge_enabled) {
surrogateKeysCacheBackends.push(
new VarnishHttpCacheBackend(serverOptions.varnish_host, serverOptions.varnish_http_port)
);
}
if (!!serverOptions.fastly.enabled && !!serverOptions.fastly.apiKey && !!serverOptions.fastly.serviceId) {
surrogateKeysCacheBackends.push(
new FastlyCacheBackend(serverOptions.fastly.apiKey, serverOptions.fastly.serviceId)
);
}
var surrogateKeysCache = new SurrogateKeysCache(surrogateKeysCacheBackends);
function invalidateNamedMap (owner, templateName) {
surrogateKeysCache.invalidate(new NamedMapsCacheEntry(owner, templateName), function(err) {
@ -46,12 +58,9 @@ var CartodbWindshaft = function(serverOptions) {
}
});
}
if (serverOptions.varnish_purge_enabled) {
['update', 'delete'].forEach(function(eventType) {
templateMaps.on(eventType, invalidateNamedMap);
});
}
['update', 'delete'].forEach(function(eventType) {
templateMaps.on(eventType, invalidateNamedMap);
});
// boot
var ws = new Windshaft.Server(serverOptions);