From c8fffe21dcf828824e7a8d84395945583ca5f285 Mon Sep 17 00:00:00 2001 From: rsteube Date: Wed, 15 Mar 2023 11:57:25 +0100 Subject: [PATCH] cache: fix cache checksum checksum needs to be regenerated after invocation --- action.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/action.go b/action.go index ba08d99bc..53c4c84f1 100644 --- a/action.go +++ b/action.go @@ -31,17 +31,22 @@ func (a Action) Cache(timeout time.Duration, keys ...pkgcache.Key) Action { cachedCallback := a.callback _, file, line, _ := runtime.Caller(1) // generate uid from wherever Cache() was called a.callback = func(c Context) Action { - if cacheFile, err := cache.File(file, line, keys...); err == nil { - if cached, err := cache.Load(cacheFile, timeout); err == nil { - return Action{meta: cached.Meta, rawValues: cached.Values} - } - invokedAction := (Action{callback: cachedCallback}).Invoke(c) - if invokedAction.meta.Messages.IsEmpty() { + cacheFile, err := cache.File(file, line, keys...) + if err != nil { + return cachedCallback(c) + } + + if cached, err := cache.Load(cacheFile, timeout); err == nil { + return Action{meta: cached.Meta, rawValues: cached.Values} + } + + invokedAction := (Action{callback: cachedCallback}).Invoke(c) + if invokedAction.meta.Messages.IsEmpty() { + if cacheFile, err := cache.File(file, line, keys...); err == nil { // regenerate as cache keys might have changed due to invocation _ = cache.Write(cacheFile, invokedAction.export()) } - return invokedAction.ToA() } - return cachedCallback(c) + return invokedAction.ToA() } } return a