diff --git a/lib/cartodb/api/api-router.js b/lib/cartodb/api/api-router.js index 14c7acec..60946a78 100644 --- a/lib/cartodb/api/api-router.js +++ b/lib/cartodb/api/api-router.js @@ -161,10 +161,6 @@ module.exports = class ApiRouter { layergroupAffectedTablesCache ); - ['update', 'delete'].forEach(function(eventType) { - templateMaps.on(eventType, namedMapProviderCache.invalidate.bind(namedMapProviderCache)); - }); - const collaborators = { analysisStatusBackend, attributesBackend, diff --git a/lib/cartodb/cache/named_map_provider_cache.js b/lib/cartodb/cache/named_map_provider_cache.js index c65a4bca..94ca074c 100644 --- a/lib/cartodb/cache/named_map_provider_cache.js +++ b/lib/cartodb/cache/named_map_provider_cache.js @@ -8,6 +8,7 @@ var templateName = require('../backends/template_maps').templateName; var LruCache = require("lru-cache"); const TEN_MINUTES_IN_MILLISECONDS = 1000 * 60 * 10; +const ACTIONS = ['update', 'delete']; function NamedMapProviderCache( templateMaps, @@ -25,6 +26,8 @@ function NamedMapProviderCache( this.affectedTablesCache = affectedTablesCache; this.providerCache = new LruCache({ max: 2000, maxAge: TEN_MINUTES_IN_MILLISECONDS }); + + ACTIONS.forEach(action => templateMaps.on(action, (...args) => this.invalidate(...args))); } module.exports = NamedMapProviderCache;