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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user