Closed advancedtw closed 1 year ago
You can return a response with caching headers, this can be cached as your will.
return response$(myData, { headers: {...} });
somthing like that right?
const adder = query$({
queryFn: async ({ payload }) => {
const result = payload.a + payload.b;
return response$(result, {
headers: {
"Cache-Control": "public, max-age=604800",
},
});
},
key: "adding",
schema: z.object({
a: z.number().max(5),
b: z.number().max(10),
}),
});
i'm still hitting the server on signal change. am i missing something obvious?
yep exactly, response$ is basically just a way to return an actual web api response, you can send any header you wish, in this case cache control should work.
const ONE_DAY_IN_SECONDS = 60 * 60 * 24;
return response$(Math.sqrt(70), {
headers: {
'cache-control': `s-maxage=1, stale-while-revalidate=${ONE_DAY_IN_SECONDS}`,
},
});
still the same I have tried other cache control settings but it's still getting called. the request headers are set as expected which is good but the browser doesn't seem to care. could it be because the method is POST instead of GET? have you managed to make it work on your side ?
It should be, will try it out and lyk
https://github.com/OrJDev/prpc/commit/0fd19d863cf1952d3ea74b65345fdd871d5994cb
I thought this was the issue, but looks like it still doesn't cache it? I assume it is something within SolidStart, should maybe open an issue and ask how can we cache data using server$ (as query$ is essentially just server$ with utilities)
ok thanks for the support. I will try a few things on my side before opening a issue.
how are we supposed to handle caching ? I was under the impression that @tanstack/solid-query would do the caching but the server query seems to always be run even with the same arguments.