From fb53ae69804bdc40e2db49b40bb0415a69817941 Mon Sep 17 00:00:00 2001 From: Rijk van Zanten Date: Wed, 15 Sep 2021 15:46:12 -0400 Subject: [PATCH] Don't flush schema cache on content update (#8056) --- api/src/cache.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/api/src/cache.ts b/api/src/cache.ts index 3371a6bed7..276f54b337 100644 --- a/api/src/cache.ts +++ b/api/src/cache.ts @@ -16,7 +16,7 @@ export function getCache(): { cache: Keyv | null; schemaCache: Keyv | null } { } if (env.CACHE_SCHEMA !== false && schemaCache === null) { - schemaCache = getKeyvInstance(typeof env.CACHE_SCHEMA === 'string' ? ms(env.CACHE_SCHEMA) : undefined); + schemaCache = getKeyvInstance(typeof env.CACHE_SCHEMA === 'string' ? ms(env.CACHE_SCHEMA) : undefined, '_schema'); schemaCache.on('error', (err) => logger.warn(err, `[cache] ${err}`)); } @@ -29,21 +29,25 @@ export async function flushCaches(): Promise { await cache?.clear(); } -function getKeyvInstance(ttl: number | undefined): Keyv { +function getKeyvInstance(ttl: number | undefined, namespaceSuffix?: string): Keyv { switch (env.CACHE_STORE) { case 'redis': - return new Keyv(getConfig('redis', ttl)); + return new Keyv(getConfig('redis', ttl, namespaceSuffix)); case 'memcache': - return new Keyv(getConfig('memcache', ttl)); + return new Keyv(getConfig('memcache', ttl, namespaceSuffix)); case 'memory': default: - return new Keyv(getConfig('memory', ttl)); + return new Keyv(getConfig('memory', ttl, namespaceSuffix)); } } -function getConfig(store: 'memory' | 'redis' | 'memcache' = 'memory', ttl: number | undefined): Options { +function getConfig( + store: 'memory' | 'redis' | 'memcache' = 'memory', + ttl: number | undefined, + namespaceSuffix = '' +): Options { const config: Options = { - namespace: env.CACHE_NAMESPACE, + namespace: `${env.CACHE_NAMESPACE}${namespaceSuffix}`, ttl, };