Update cache key names

- All cache keys are now structured as 'gradle-<cache-name>-<protocol-version>
  - This ensures that extracted entries are prefixed and versioned consistently
- Avoid using custom cache-key prefix for extracted entries. This should reduce the
  churn in integration tests that require some level of cache isolation.
This commit is contained in:
daz
2024-04-08 14:23:37 -06:00
parent 3335c16182
commit 498f0e409b
3 changed files with 12 additions and 11 deletions

View File

@@ -10,9 +10,10 @@ import {cacheDebug, hashFileNames, isCacheDebuggingEnabled, restoreCache, saveCa
import {BuildResult, loadBuildResults} from '../build-results'
import {CacheConfig} from '../input-params'
import {getCacheKeyPrefix} from './cache-key'
import {getCacheKeyBase} from './cache-key'
const SKIP_RESTORE_VAR = 'GRADLE_BUILD_ACTION_SKIP_RESTORE'
const CACHE_PROTOCOL_VERSION = 'v1'
/**
* Represents the result of attempting to load or store an extracted cache entry.
@@ -244,22 +245,20 @@ abstract class AbstractEntryExtractor {
}
protected createCacheKeyFromFileNames(artifactType: string, files: string[]): string {
const cacheKeyPrefix = getCacheKeyPrefix()
const relativeFiles = files.map(x => path.relative(this.gradleUserHome, x))
const key = hashFileNames(relativeFiles)
cacheDebug(`Generating cache key for ${artifactType} from file names: ${relativeFiles}`)
return `${cacheKeyPrefix}${artifactType}-${key}`
return `${getCacheKeyBase(artifactType, CACHE_PROTOCOL_VERSION)}-${key}`
}
protected async createCacheKeyFromFileContents(artifactType: string, pattern: string): Promise<string> {
const cacheKeyPrefix = getCacheKeyPrefix()
const key = await glob.hashFiles(pattern)
cacheDebug(`Generating cache key for ${artifactType} from files matching: ${pattern}`)
return `${cacheKeyPrefix}${artifactType}-${key}`
return `${getCacheKeyBase(artifactType, CACHE_PROTOCOL_VERSION)}-${key}`
}
// Run actions sequentially if debugging is enabled