MCPcopy
hub / github.com/directus/directus / getCache

Function getCache

api/src/cache.ts:54–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52}
53
54export function getCache(): {
55 cache: Keyv | null;
56 systemCache: Keyv;
57 deploymentCache: Keyv;
58 localSchemaCache: Keyv;
59 lockCache: Keyv;
60} {
61 if (env['CACHE_ENABLED'] === true && cache === null) {
62 validateEnv(['CACHE_NAMESPACE', 'CACHE_TTL', 'CACHE_STORE']);
63 cache = getKeyvInstance(env['CACHE_STORE'] as Store, getMilliseconds(env['CACHE_TTL']));
64 cache.on('error', (err) => logger.warn(err, `[cache] ${err}`));
65 }
66
67 if (systemCache === null) {
68 systemCache = getKeyvInstance(env['CACHE_STORE'] as Store, getMilliseconds(env['CACHE_SYSTEM_TTL']), '_system');
69 systemCache.on('error', (err) => logger.warn(err, `[system-cache] ${err}`));
70 }
71
72 if (deploymentCache === null) {
73 const ttl = getMilliseconds(env['CACHE_DEPLOYMENT_TTL']) || 5000; // Default 5s
74 deploymentCache = getKeyvInstance(env['CACHE_STORE'] as Store, ttl, '_deployment');
75 deploymentCache.on('error', (err) => logger.warn(err, `[deployment-cache] ${err}`));
76 }
77
78 if (localSchemaCache === null) {
79 localSchemaCache = getKeyvInstance('memory', getMilliseconds(env['CACHE_SYSTEM_TTL']), '_schema');
80 localSchemaCache.on('error', (err) => logger.warn(err, `[schema-cache] ${err}`));
81 }
82
83 if (lockCache === null) {
84 lockCache = getKeyvInstance(env['CACHE_STORE'] as Store, undefined, '_lock');
85 lockCache.on('error', (err) => logger.warn(err, `[lock-cache] ${err}`));
86 }
87
88 return { cache, systemCache, deploymentCache, localSchemaCache, lockCache };
89}
90
91export async function flushCaches(forced?: boolean): Promise<void> {
92 const { cache } = getCache();

Callers 15

flushCachesFunction · 0.70
clearSystemCacheFunction · 0.70
setSystemCacheFunction · 0.70
getSystemCacheFunction · 0.70
fetchContextDataFunction · 0.50
cache.tsFile · 0.50
respond.tsFile · 0.50
trackCacheMetricFunction · 0.50
cacheClearFunction · 0.50
listProviderProjectsMethod · 0.50
getProviderProjectMethod · 0.50
constructorMethod · 0.50

Calls 4

validateEnvFunction · 0.85
getKeyvInstanceFunction · 0.85
getMillisecondsFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected