From 84a5c7a2747c01dc8813aab33740da195c0b449f Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Wed, 2 Oct 2024 21:55:36 -0400 Subject: [PATCH] chore(core): expose utility to determine if db cache is enabled (#28262) ## Current Behavior There is no function to determine if the db cache is enabled ## Expected Behavior There is a function to determine if the db cache is enabled. ## Related Issue(s) Fixes # --- packages/nx/src/tasks-runner/cache.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/tasks-runner/cache.ts b/packages/nx/src/tasks-runner/cache.ts index 33882bcb210d9..55447db4bbea3 100644 --- a/packages/nx/src/tasks-runner/cache.ts +++ b/packages/nx/src/tasks-runner/cache.ts @@ -29,11 +29,17 @@ export type CachedResult = { }; export type TaskWithCachedResult = { task: Task; cachedResult: CachedResult }; +export function dbCacheEnabled(nxJson: NxJsonConfiguration = readNxJson()) { + return ( + process.env.NX_DISABLE_DB !== 'true' && + (nxJson.enableDbCache === true || process.env.NX_DB_CACHE === 'true') + ); +} + // Do not change the order of these arguments as this function is used by nx cloud export function getCache(options: DefaultTasksRunnerOptions): DbCache | Cache { const nxJson = readNxJson(); - return process.env.NX_DISABLE_DB !== 'true' && - (nxJson.enableDbCache === true || process.env.NX_DB_CACHE === 'true') + return dbCacheEnabled(nxJson) ? new DbCache({ // Remove this in Nx 21 nxCloudRemoteCache: isNxCloudUsed(nxJson) ? options.remoteCache : null,