#Module function cache invalidation

1 messages · Page 1 of 1 (latest)

wind anchor
#

I am doing a simple API call to our security gateway to obtain an oauth token. It's just a REST POST. I have a single withExec that does the call and I am invoking the function and passing in my user/pass via CLI.

I have added a CACHE_BUSTER right before the withExec. However, every time I call the function it gives me the same token (because the withExec is cached). According to the above, shouldn't I get a new token every time?

One thing to note is that the withExec is writing my token to a file within the container. I am then using File.Contents() to print it after parsing the json. IDK if that has any effect.

I can see on the TUI that the withExec specifically is cached though

dire pond
#

Just to try to disambiguate here, if I have this function:

package main

import (
    "context"
    "fmt"
    "time"
)

type Test struct{}

func (m *Test) Fn(ctx context.Context) (string, error) {
    return dag.Container().From("alpine:3.18").
        WithEnvVariable("CACHEBUSTER", fmt.Sprintf("%d", time.Now().UnixNano())).
        WithExec([]string{"sh", "-c", "echo $CACHEBUSTER"}).
        Stdout(ctx)
}

and then repeatedly run dagger call fn, I get different output every time.

Are you calling the withExec multiple times within the same module function? If so, you'd need a different cache buster each time.

wind anchor
#

Hmm, I am not, I only have 1 withExec

#

I am actually not using the CACHEBUSTER value within the withExec. i wonder if that's what's causing it to be re-run in your case? My withExec itself is static. It's doing a curl and appending the result to a file.

dire pond
# wind anchor I am actually not using the CACHEBUSTER value within the withExec. i wonder if t...

No that shouldn't matter, the caching is based on the definition of the operation and the inputs to it, so echo $CACHEBUSTER won't impact that.

i.e. I get the same behavior of a new value each time even if I change it to not use echo $CACHEBUSTER:

func (m *Test) Fn(ctx context.Context) (string, error) {
    return dag.Container().From("alpine:3.18").
        WithEnvVariable("CACHEBUSTER", fmt.Sprintf("%d", time.Now().UnixNano())).
        WithExec([]string{"sh", "-c", "echo $RANDOM"}).
        Stdout(ctx)
}
wind anchor
#

ok I found the issue. Purely me being a dummy. My cachebuster was

WithEnvVariable("CACHE_BUSTER", strconv.Itoa(time.Now().Day())).

Since i'm in the module conversion mode i copy pasted my vanilla dagger code and didn't realize my CACHE_BUSTER was a daily one.