Caching with Convex
Hi, I am using the action-cache in my app, however there's a problem with cache.fetch.
Suppose I have an action summarizePaperInternal that returns a string, and I want to cache it, so I follow the docs at https://github.com/get-convex/action-cache, and create an ActionCache. I would assume that after defining the action, the return of the ActionCache will be same as my action. However that doesn't appear to be the case and ActionCache.fetch returns
any
.


20 Replies
Speaking of the docs, there seems to be a bug/error/typo in it at https://github.com/get-convex/action-cache.
myFunction
just calls cache.fetch but doesn't actually return any results of the fetched value from the cache.
Good catches here, thanks for that. PR up: https://github.com/get-convex/action-cache/pull/7
released in
v0.2.7
Ok but my main problem is still the return type of cache.fetch
It's returning any, and I can't deploy my app because of it unless I type cast
NVM, I see the PR fixes the return type too. Let me try, one sec.
Looks like it's been fixed. Thanks guys, lightspeed.
Unrelated to this, but I've pointed out a bug on the landing page two times now but no one seems to respond @erquhart @Ian
yeah thanks for that! I already saw it posted by Wayne in our internal chat this morning
Cool
Seems like I spoke too soon.
This is a really weird bug.
When I only store the result in a variable and don't return it, the type is correctly inferred

However
As soon as I return the result, the type changes to
any
. What the fuck?
@erquhart Sorry for the ping, but I see you're online. Could you take a look at this? This entire caching bug has been blocking me for a good 2+ days now.
This seems like a common issue related to circular types. If you add return types to all the related
handler
functions that hopefully fixes it
essentially when the return type of one function internal.foo.one
depends on the return type type of internal.foo.two
, unfortunately the type of internal
itself depends on both of them. So one
's return value ends up depending on itself.Actions | Convex Developer Hub
Actions can call third party services to do things such as processing a payment
Interesting.
I guess you'll probably need to update the docs again, because this won't work out of the box then:

good call - it's a good practice to put out there too. Do you have time to cut a PR improving the docs?
I can do it, but there's a problem
In the example, the return type of
generateLLMResponse
isn't known, so inside myFunction
, we can't explicitly write out the return type.
you can take some liberties - that's just as an illustrative example. e.g.
{ text: string, usage: Usage }
or just string
even
fwiw the example.ts
is correct, but b/c it was explicitly typing the return valueI think
ReturnType<generateLLMResponse>
might work
I'll just do a generic pr with string.pr is up https://github.com/get-convex/action-cache/pull/8
---
fyi:
doing
won't work. runs into same inference issue.
there's only one way to fix it:
which is typing the handler
GitHub
explicitly type result by NexWasTaken · Pull Request #8 · get-con...
Addresses issues raised in Discord: https://discord.com/channels/1019350475847499849/1377179000643915808
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute...