#Disable Cache for a Module's Function

1 messages ยท Page 1 of 1 (latest)

coral elm
#

Hey ๐Ÿ‘‹

I'm currently writing a module to interact with GitHub and facing some issues with the caching.

Basically I'd like to check if a PR is merged or not. So I've written a function that looks like this:

func (m *Github) IsMerged(ctx context.Context, owner, repo string, number int) (bool, error) {
    client := github.NewClient(nil).WithAuthToken(m.Token)
    ok, _, err := client.PullRequests.IsMerged(ctx, owner, repo, number)
    return ok, err
}

I can then call the function from another module like so: dag.Github().IsMerged("dagger", "dagger", 1)
This works very well.

However, the caching is causing issues when I try to implement logic like waiting until the PR is merged.
In my consumer module, if I call the IsMerged function multiple times in a row then I always get a cache hit to the first call.
This makes logic such as while not IsMerged; sleep 5 and means that I cannot trust the output of IsMerged since it might be cached from a long time ago.

Is there a way I can flag a function so that it is never cached?

Otherwise I think I'd have to add a cachebuster parameter to make each call signature unique?

Thanks for your help!

hearty vessel
#

Hey Vincent!

At the moment the only mechanism for invalidating the cache would be to use a parameter like you say and change its value each time. You can make the parameter optional in case you are also calling this function from the CLI or other places!

coral elm
#

It would be great if we could annotate functions so the codegen takes care of this and we don't have to trust the user ๐Ÿ™‚
e.g.

// +cache=false
func (m *Github) IsMerged(...) (bool, error) {
feral garnet
ripe path
feral garnet
coral elm
#

Yup I've ended up create another function WaitUntilMerged in the same module where there is no caching. However users of my module might still have the issue so I added the optional cachebuster parameter.
Would love a generic solution like shown in the issue with // +cache=false and // +ttl=10s!

feral garnet
#

for the IsMerged I mean..

#

having said that, the WaitUntilMerged helper also seems handy