Josesito
Explore posts from serversHow does `query` cache actually work?
---
So if two separate routes use the same
query
with the same key and arguments, and both of them get loaded within less than 5 seconds, the second route will use the cached value, correct?
Even if the routes get loaded from different browsers.16 replies
How does `query` cache actually work?
Oh! That's awesome that it uses the arguments to key the hash, this makes it make sense, and this also makes me understand the
keyFor
method.
I think this is the most that the docs mention about the arguments of the function that gets passed into the first param of cache()
:
When this newly created function is called for the first time with a specific set of argumentsTime permitting, assuming no one else gets to it before myself, I may try to contribute to the docs if someone else helps me read-proof and re-phrase when I make a PR.
16 replies
How does `query` cache actually work?
is the
query
value scoped to the route of a given request?
For example...
- Given this query
- Given this route:
solid/src/routes/product/[id].tsx
- Given this preload
:
Here I am using the slug [id]
to determine the data that ought to be loaded. However, the cache key for query
is a common key that does not differ between two different id
s.
I.E.
- http://localhost:3000/product/thang
- http://localhost:3000/product/foo
Each of these routes should load very different data, but both use the same string key for their query
cache: "productById"
.
If both URLs are loaded almost at the same time, will the second route use the cached value from the first route?
Now, people have been using the word "global" to describe the cache, but that is not a term that I understand as I do not know the implications. The most "global" definition would indicate that the first value to get cached will determine the value of the second request.16 replies
How does `query` cache actually work?
This is a wonderful explanation @peerreynders! Thank you so much. It would be great to add all of your thoughts into the documentation for future travelers. As far as my curiosity is concerned, satisfaction has been surpassed. Even your explanation of "preload" in this context is much better than trying to understand each part in isolation as you say, I had not understood this interaction yet until you connected the dots for me. Likewise with "action".
16 replies
How does `query` cache actually work?
Another piece of valuable information that is missing from the docs is this:
- https://discord.com/channels/722131463138705510/1312420332333961216
According to these users, the cache does not persist across requests. This, for instance, has very different implications from a "cache that invalidates after 10 seconds"
Assuming that those comments are accurate, ofwhich I am not in a good position to verify
16 replies