Josesito
Josesito
Explore posts from servers
SSolidJS
Created by Josesito on 1/18/2025 in #support
How 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
SSolidJS
Created by Josesito on 1/18/2025 in #support
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 arguments
Time 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
SSolidJS
Created by Josesito on 1/18/2025 in #support
How does `query` cache actually work?
is the query value scoped to the route of a given request? For example... - Given this query
export const getProduct = query(async (slug: string) => {
"use server";
try {
return await directus.request(readItem("product", slug));
} catch (e) {
return null;
}
}, "productById")
export const getProduct = query(async (slug: string) => {
"use server";
try {
return await directus.request(readItem("product", slug));
} catch (e) {
return null;
}
}, "productById")
- Given this route: solid/src/routes/product/[id].tsx - Given this preload:
export const route = {
preload: (({ location, params }) => {
if (location.pathname) {
return getProduct(params.id)
}
})
} satisfies RouteProps<string>
export const route = {
preload: (({ location, params }) => {
if (location.pathname) {
return getProduct(params.id)
}
})
} satisfies RouteProps<string>
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 ids. 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
SSolidJS
Created by Josesito on 1/18/2025 in #support
How does `query` cache actually work?
Kudos to the API design too, this is all radically elegant.
16 replies
SSolidJS
Created by Josesito on 1/18/2025 in #support
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
SSolidJS
Created by Josesito on 1/18/2025 in #support
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
SSolidJS
Created by Josesito on 1/18/2025 in #support
How does `query` cache actually work?
Oh yeah, it would be great to add this information to the documentation, and it should be as accurate as it can be, for me there is a difference between "1 second" and "10 seconds", and I would like to know such details for sure.
16 replies
SSolidJS
Created by sh03 on 11/30/2024 in #support
Is `query` cached per request or globally?
does this mean that on a separate request it will fetch the data again?
4 replies