MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/buildpacks / CheckCacheExpiration

Function CheckCacheExpiration

pkg/java/java.go:171–191  ·  view source on GitHub ↗

CheckCacheExpiration clears the m2 layer and sets a new expiry timestamp when the cache is past expiration.

(ctx *gcp.Context, m2CachedRepo *libcnb.Layer)

Source from the content-addressed store, hash-verified

169
170// CheckCacheExpiration clears the m2 layer and sets a new expiry timestamp when the cache is past expiration.
171func CheckCacheExpiration(ctx *gcp.Context, m2CachedRepo *libcnb.Layer) error {
172 t := time.Now()
173 expiry := ctx.GetMetadata(m2CachedRepo, expiryTimestampKey)
174 if expiry != "" {
175 var err error
176 t, err = time.Parse(dateFormat, expiry)
177 if err != nil {
178 ctx.Debugf("Could not parse expiration date %q, assuming now: %v", expiry, err)
179 }
180 }
181 if t.After(time.Now()) {
182 return nil
183 }
184
185 ctx.Debugf("Cache expired on %v, clearing", t)
186 if err := ctx.ClearLayer(m2CachedRepo); err != nil {
187 return fmt.Errorf("clearing layer %q: %w", m2CachedRepo.Name, err)
188 }
189 ctx.SetMetadata(m2CachedRepo, expiryTimestampKey, time.Now().Add(repoExpiration).Format(dateFormat))
190 return nil
191}
192
193// MvnCmd returns the command that should be used to invoke maven for this build.
194func MvnCmd(ctx *gcp.Context) (string, error) {

Callers 4

BuildFnFunction · 0.92
BuildFnFunction · 0.92
TestCheckCacheNewDateHitFunction · 0.85

Calls 5

GetMetadataMethod · 0.80
DebugfMethod · 0.80
ClearLayerMethod · 0.80
SetMetadataMethod · 0.80
AddMethod · 0.45

Tested by 2

TestCheckCacheNewDateHitFunction · 0.68