diff --git a/src/cache-gradle-user-home.ts b/src/cache-gradle-user-home.ts index e1ac2f4..1fe8bb4 100644 --- a/src/cache-gradle-user-home.ts +++ b/src/cache-gradle-user-home.ts @@ -32,8 +32,7 @@ export class GradleUserHomeCache extends AbstractCache { super('gradle', 'Gradle User Home') } - async restore(): Promise { - await super.restore() + async afterRestore(): Promise { await this.reportCacheEntrySize('as restored from cache') await this.restoreCommonArtifacts() await this.reportCacheEntrySize('after restoring common artifacts') @@ -119,9 +118,8 @@ export class GradleUserHomeCache extends AbstractCache { core.info('-----------------------') } - async save(): Promise { + async beforeSave(): Promise { await this.saveCommonArtifacts() - await super.save() } private async saveCommonArtifacts(): Promise { diff --git a/src/cache-utils.ts b/src/cache-utils.ts index a5531b5..acf862e 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -109,6 +109,9 @@ export abstract class AbstractCache { core.info( `${this.cacheDescription} restored from cache key: ${cacheResult}` ) + + await this.afterRestore() + return } @@ -134,6 +137,8 @@ export abstract class AbstractCache { } } + protected async afterRestore(): Promise {} + async save(): Promise { if (!this.cacheOutputExists()) { this.debug(`No ${this.cacheDescription} to cache.`) @@ -157,6 +162,8 @@ export abstract class AbstractCache { return } + await this.beforeSave() + core.info( `Caching ${this.cacheDescription} with cache key: ${cacheKey}` ) @@ -166,6 +173,8 @@ export abstract class AbstractCache { return } + protected async beforeSave(): Promise {} + protected async saveCache( cachePath: string[], cacheKey: string