Move invalidation closer to its definition

This commit is contained in:
Daniel García Aubert 2019-09-13 17:42:56 +02:00
parent 3d2f554be9
commit 1bb6a2ac0d
2 changed files with 3 additions and 4 deletions

View File

@ -161,10 +161,6 @@ module.exports = class ApiRouter {
layergroupAffectedTablesCache layergroupAffectedTablesCache
); );
['update', 'delete'].forEach(function(eventType) {
templateMaps.on(eventType, namedMapProviderCache.invalidate.bind(namedMapProviderCache));
});
const collaborators = { const collaborators = {
analysisStatusBackend, analysisStatusBackend,
attributesBackend, attributesBackend,

View File

@ -8,6 +8,7 @@ var templateName = require('../backends/template_maps').templateName;
var LruCache = require("lru-cache"); var LruCache = require("lru-cache");
const TEN_MINUTES_IN_MILLISECONDS = 1000 * 60 * 10; const TEN_MINUTES_IN_MILLISECONDS = 1000 * 60 * 10;
const ACTIONS = ['update', 'delete'];
function NamedMapProviderCache( function NamedMapProviderCache(
templateMaps, templateMaps,
@ -25,6 +26,8 @@ function NamedMapProviderCache(
this.affectedTablesCache = affectedTablesCache; this.affectedTablesCache = affectedTablesCache;
this.providerCache = new LruCache({ max: 2000, maxAge: TEN_MINUTES_IN_MILLISECONDS }); this.providerCache = new LruCache({ max: 2000, maxAge: TEN_MINUTES_IN_MILLISECONDS });
ACTIONS.forEach(action => templateMaps.on(action, (...args) => this.invalidate(...args)));
} }
module.exports = NamedMapProviderCache; module.exports = NamedMapProviderCache;