erquhart
erquhart14mo ago

paginated queries

Do paginated queries not get cached?
9 Replies
mikeysee
mikeysee14mo ago
I too have been wondering about this.. It would be a tricky one to do I suspect?
lee
lee14mo ago
I think they should be cached. Are you observing that they don't get cached?
erquhart
erquhartOP14mo ago
I had a function in dev that I switched to paginated and caching seems to have stopped. But I just checked and my main paginated query in production does get cached, so not sure what I did to upset the one I'm working on. My understanding is that, if inputs don't change, I get a cached response, but there has to be other variables. Some queries get cached reliably and others just don't. It seems the more busy a query is the more likely it is to not produce cached responses, even if the inputs are simple and don't change.
lee
lee14mo ago
it's a function of inputs and the data accessed by the query. basically the same "realtime subscription" feature of useQuery is also used on the server to invalidate the cache
erquhart
erquhartOP14mo ago
Okay. Is it possible that indirection in the actual ctx.db calls (calling a function that calls a function that calls a function vs calling direct) can somehow impact this?
lee
lee14mo ago
how you call ctx.db shouldn't matter, although layers of indirection could hide things. like if you're doing security checks against ctx.auth, the query will only be cached for that auth.
erquhart
erquhartOP14mo ago
Does calling auth.getUserIdentity() count as a security check? That's my only interaction with the auth object I believe
lee
lee14mo ago
if you call auth.getUserIdentity(), then your query depends on the authenticated user and the query won't be cached across users
erquhart
erquhartOP14mo ago
That's what I figured. The misses I'm seeing are for a single user. Maybe not much to assess here, I'll circle back when I have wide usage and meaningful data.

Did you find this page helpful?