CheckCacheExpiration clears the m2 layer and sets a new expiry timestamp when the cache is past expiration.
(ctx *gcp.Context, m2CachedRepo *libcnb.Layer)
| 169 | |
| 170 | // CheckCacheExpiration clears the m2 layer and sets a new expiry timestamp when the cache is past expiration. |
| 171 | func 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. |
| 194 | func MvnCmd(ctx *gcp.Context) (string, error) { |