@@ -33,6 +33,7 @@ export default class ProjectBuildCache {
3333 #dependencyReader;
3434 #resourceIndex;
3535 #requiresInitialBuild;
36+ #isNewOrModified;
3637
3738 #invalidatedTasks = new Map ( ) ;
3839
@@ -332,6 +333,7 @@ export default class ProjectBuildCache {
332333 }
333334 // Reset current project reader
334335 this . #currentProjectReader = null ;
336+ this . #isNewOrModified = true ;
335337 }
336338
337339 /**
@@ -579,6 +581,7 @@ export default class ProjectBuildCache {
579581 stageId , stageSignature , stageCache . resourceMetadata ) ;
580582 this . #project. setResultStage ( reader ) ;
581583 this . #project. useResultStage ( ) ;
584+ this . #isNewOrModified = false ;
582585 return true ;
583586 }
584587
@@ -695,9 +698,10 @@ export default class ProjectBuildCache {
695698 * @returns {Promise<void> }
696699 */
697700 async storeCache ( buildManifest ) {
698- log . verbose ( `Storing build cache for project ${ this . #project. getName ( ) } ` +
699- `with build signature ${ this . #buildSignature} ` ) ;
700701 if ( ! this . #buildManifest) {
702+ log . verbose ( `Storing build manifest for project ${ this . #project. getName ( ) } ` +
703+ `with build signature ${ this . #buildSignature} ` ) ;
704+ // Write build manifest if it wasn't loaded from cache before
701705 this . #buildManifest = buildManifest ;
702706 await this . #cacheManager. writeBuildManifest ( this . #project. getId ( ) , this . #buildSignature, buildManifest ) ;
703707 }
@@ -707,11 +711,20 @@ export default class ProjectBuildCache {
707711
708712 // Store task caches
709713 for ( const [ taskName , taskCache ] of this . #taskCache) {
710- await this . #cacheManager. writeTaskMetadata ( this . #project. getId ( ) , this . #buildSignature, taskName ,
711- taskCache . toCacheObject ( ) ) ;
714+ if ( taskCache . isNewOrModified ( ) ) {
715+ log . verbose ( `Storing task cache metadata for task ${ taskName } in project ${ this . #project. getName ( ) } ` +
716+ `with build signature ${ this . #buildSignature} ` ) ;
717+ await this . #cacheManager. writeTaskMetadata ( this . #project. getId ( ) , this . #buildSignature, taskName ,
718+ taskCache . toCacheObject ( ) ) ;
719+ }
712720 }
713721
722+ if ( ! this . #isNewOrModified) {
723+ return ;
724+ }
714725 // Store stage caches
726+ log . verbose ( `Storing stage caches for project ${ this . #project. getName ( ) } ` +
727+ `with build signature ${ this . #buildSignature} ` ) ;
715728 const stageQueue = this . #stageCache. flushCacheQueue ( ) ;
716729 await Promise . all ( stageQueue . map ( async ( [ stageId , stageSignature ] ) => {
717730 const { stage} = this . #stageCache. getCacheForSignature ( stageId , stageSignature ) ;
@@ -739,6 +752,8 @@ export default class ProjectBuildCache {
739752 } ) ) ;
740753
741754 // Finally store index cache
755+ log . verbose ( `Storing resource index cache for project ${ this . #project. getName ( ) } ` +
756+ `with build signature ${ this . #buildSignature} ` ) ;
742757 const indexMetadata = this . #resourceIndex. toCacheObject ( ) ;
743758 await this . #cacheManager. writeIndexCache ( this . #project. getId ( ) , this . #buildSignature, {
744759 ...indexMetadata ,
0 commit comments