Add cache connection fallbacks (#7226)

This commit is contained in:
Rijk van Zanten
2021-08-05 22:27:10 +02:00
committed by GitHub
parent 6e92b9247e
commit faa71c7595
4 changed files with 51 additions and 9 deletions

View File

@@ -28,13 +28,28 @@ export async function getSchema(options?: {
let result: SchemaOverview;
if (env.CACHE_SCHEMA !== false && schemaCache) {
const cachedSchema = (await schemaCache.get('schema')) as SchemaOverview;
let cachedSchema;
try {
cachedSchema = (await schemaCache.get('schema')) as SchemaOverview;
} catch (err) {
logger.warn(err, `[schema-cache] Couldn't retrieve cache. ${err}`);
}
if (cachedSchema) {
result = cachedSchema;
} else {
result = await getDatabaseSchema(database, schemaInspector);
await schemaCache.set('schema', result, typeof env.CACHE_SCHEMA === 'string' ? ms(env.CACHE_SCHEMA) : undefined);
try {
await schemaCache.set(
'schema',
result,
typeof env.CACHE_SCHEMA === 'string' ? ms(env.CACHE_SCHEMA) : undefined
);
} catch (err) {
logger.warn(err, `[schema-cache] Couldn't save cache. ${err}`);
}
}
} else {
result = await getDatabaseSchema(database, schemaInspector);