T
TanStack4w ago
harsh-harlequin

Server side query caching with TanStack Start and Query

Is it possible to cache an api call on the server side using TanStack Query and Start? Example: my API provide an endpoint that returns a list of states given a country code. This list will not change during the application lifecycle, and don't have any problem if shared by all users.
5 Replies
rival-black
rival-black4w ago
I don't think Start really does this besides messing with cache-age headers. Nextjs has some of this I think. By states you mean US states, German Lander, Canadian provinces, Irish counties etc?
harsh-harlequin
harsh-harlequinOP4w ago
Yes sir About Next: I don't use drugs.
eastern-cyan
eastern-cyan4w ago
You mean like Nextjs' SSG's generated at build time shenanigans? Start has https://tanstack.com/start/latest/docs/framework/react/static-server-functions but it is not "cache", just executed at build time and outputted as json file
Static Server Functions | TanStack Start React Docs
What are Static Server Functions? Static server functions are server functions that are executed at build time and cached as static assets when using prerendering/static-generation. They can be set to...
rival-black
rival-black4w ago
For those top-level administrative units, I'd just have a query function for each country with a stale and gcTime of a week. It feel like having a few thousand of those units client side isn't the most beneficial. On the server side you might be able to configure cloudflare to cache those responses in a CDN or something.
harsh-harlequin
harsh-harlequinOP4w ago
I would like to have it cached on the server side with the framework itself. I can do it by creating a cache manualy, but I expected to have it with TanStack query. OK. It was not exactly what I was expecting, but helps a bit.

Did you find this page helpful?