From 1bb6a2ac0d53998fef6d28d21ff06173689376c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Fri, 13 Sep 2019 17:42:56 +0200 Subject: [PATCH] Move invalidation closer to its definition --- lib/cartodb/api/api-router.js | 4 ---- lib/cartodb/cache/named_map_provider_cache.js | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) 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;