mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add cache connection fallbacks (#7226)
This commit is contained in:
@@ -12,12 +12,12 @@ export function getCache(): { cache: Keyv | null; schemaCache: Keyv | null } {
|
||||
if (env.CACHE_ENABLED === true && cache === null) {
|
||||
validateEnv(['CACHE_NAMESPACE', 'CACHE_TTL', 'CACHE_STORE']);
|
||||
cache = getKeyvInstance(ms(env.CACHE_TTL as string));
|
||||
cache.on('error', (err) => logger.error(err));
|
||||
cache.on('error', (err) => logger.warn(err, `[cache] ${err}`));
|
||||
}
|
||||
|
||||
if (env.CACHE_SCHEMA !== false && schemaCache === null) {
|
||||
schemaCache = getKeyvInstance(typeof env.CACHE_SCHEMA === 'string' ? ms(env.CACHE_SCHEMA) : undefined);
|
||||
schemaCache.on('error', (err) => logger.error(err));
|
||||
schemaCache.on('error', (err) => logger.warn(err, `[cache] ${err}`));
|
||||
}
|
||||
|
||||
return { cache, schemaCache };
|
||||
@@ -43,7 +43,11 @@ function getConfig(store: 'memory' | 'redis' | 'memcache' = 'memory', ttl: numbe
|
||||
|
||||
if (store === 'redis') {
|
||||
const KeyvRedis = require('@keyv/redis');
|
||||
config.store = new KeyvRedis(env.CACHE_REDIS || getConfigFromEnv('CACHE_REDIS_'));
|
||||
|
||||
config.store = new KeyvRedis(env.CACHE_REDIS || getConfigFromEnv('CACHE_REDIS_'), {
|
||||
commandTimeout: 500,
|
||||
retryStrategy: false,
|
||||
});
|
||||
}
|
||||
|
||||
if (store === 'memcache') {
|
||||
|
||||
Reference in New Issue
Block a user