Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulkar committed Mar 24, 2023
1 parent 7ffe420 commit 84b56da
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cli/internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ func (mplex *cacheMultiplexer) Fetch(anchor turbopath.AbsoluteSystemPath, key st
copy(caches, mplex.caches)
mplex.mu.RUnlock()

cacheState := ItemStatus{}
// We need to return a composite cache status from multiple caches
// Initialize the empty struct so we can assign values to it. This is similar
// to how the Exists() method works.
combinedCacheState := ItemStatus{}

// Retrieve from caches sequentially; if we did them simultaneously we could
// easily write the same file from two goroutines at once.
for i, cache := range caches {
Expand All @@ -263,9 +267,11 @@ func (mplex *cacheMultiplexer) Fetch(anchor turbopath.AbsoluteSystemPath, key st
// we have previously successfully stored in a higher-priority cache, and so the overall
// result is a success at fetching. Storing in lower-priority caches is an optimization.
_ = mplex.storeUntil(anchor, key, duration, actualFiles, i)
cacheState.Local = cacheState.Local || itemStatus.Local
cacheState.Remote = cacheState.Remote || itemStatus.Remote
return cacheState, actualFiles, duration, err

// If another cache had already set this to true, we don't need to set it again from this cache
combinedCacheState.Local = combinedCacheState.Local || itemStatus.Local
combinedCacheState.Remote = combinedCacheState.Remote || itemStatus.Remote
return combinedCacheState, actualFiles, duration, err
}
}

Expand Down

0 comments on commit 84b56da

Please sign in to comment.