Global Persisting Cache
Hiya, really confused with how i would go about having global persisting cache with tanstack start and tanstack query?
1) I see the docs only mention persisting it stuff in localstorage.. but i would like to have a global cache like nextjs.
2) Even if i do localstorage.. i get errors that localstorage is not defined
35 Replies
absent-sapphire•6mo ago
what's a "global persisting cache" for you? where? on the server, on the client ... ?
fair-roseOP•6mo ago
on the server
something everyone can access.. but its cached
so in the future it an be revalidated
or else i could just ssg
on a side note.. how do you even persist cache on the server xD... do i need to like roll my own redis and stuff?
absent-sapphire•6mo ago
you can use redis, yes
you would do the same in nextjs unless you deploy on vercel
fair-roseOP•6mo ago
not really know.. nextjs by default uses a filebased system
the .next folder
absent-sapphire•6mo ago
at runtime?
fair-roseOP•6mo ago
works on any nextjs app
absent-sapphire•6mo ago
what does it put there
fair-roseOP•6mo ago
yep
absent-sapphire•6mo ago
how does it get there
fair-roseOP•6mo ago
all of your cache files, etc
even on vercel.. it uses .next
absent-sapphire•6mo ago
so how do you cache things ?
which API
fair-roseOP•6mo ago
in next?
absent-sapphire•6mo ago
yes
fair-roseOP•6mo ago
well my golang backends expose dynamic apis.. so no caching on them.. and then in nextjs i either use the fetch cache or unstable_cache
the dynamic exports dont work with me well since i like granular caching
now with tanstack i honestly just wanted a similar way to put stuff in a file based cache.. globally
but idt tanstack start is built for that
its more for a user specific dashboard type apps right
absent-sapphire•6mo ago
isn't the .next folder just used during development?
fair-roseOP•6mo ago
nope.. even production :D
lemme show
fair-roseOP•6mo ago
our company running a nextjs app on a pt panel

fair-roseOP•6mo ago

fair-roseOP•6mo ago
its not vercel specific
absent-sapphire•6mo ago
some link to documentation would be nice. also how this works with severless setups, how does this sync across instances?
I just found some discussions that state that this folder is only used during dev and can be deleted prior to deployment ... might be wrong then?
fair-roseOP•6mo ago
cant seem to find specific documentation on the .next folder
but you can ask chatgpt to explain
absent-sapphire•6mo ago
hm how would chatgpt know if there are no docs?
fair-roseOP•6mo ago
cause its a thing lol.. the docs dont specify directly

typical-coral•6mo ago
Start has the same limitations as next, excluding vercel specific features.
So if you want a cache file, you can create and read and write to a cache file
From a server function
Or an api route
That file may die if you’re using serverless
Which would then mean you need something more persistent, like a file storage layer, distributed key value store, etc
If you could clarify, what is a feature in next that requires this “global cache”?
fair-roseOP•6mo ago
that is expected and fine with me, vercel is a big vendor lockin provider xD
ideally i host it on my vps, and in that case i can also selfhost a redis instance
i just couldnt find any good examples of a file based/redis setup.. and the stuff i did try didnt seem to work. I went through all of the projects in #start-showcase and the tanstack start examples, nobody seems to be using a server side persister
fair-roseOP•6mo ago
this is what i needed the global cache for.. those 3 words, i want it so globally it gets cached and is updated every hour for all the users

absent-sapphire•6mo ago
did you try static server functions?
https://tanstack.com/start/latest/docs/framework/react/static-server-functions#what-are-static-server-functions
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...
fair-roseOP•6mo ago
its just SSG right?
fetch on build
and then use cache for future clients
i can make a quick testing repo for you guys
the feature on nextjs vs my attempt on tanstack
i really want to use start for my codebase (i love the dev tools i cannot live without them anymore)
lmao
absent-sapphire•6mo ago
@Tanner Linsley did we ever merge the "dynamic" static server fn? https://x.com/tannerlinsley/status/1864721489309896798?t=GwfJFCBMg7h_teVsnLQFLg&s=19
Tanner Linsley (@tannerlinsley) on X
Alright, this is getting really cool. This opens up a lot of really cool use-cases and mixed static/dynamic patterns for @Tan_Stack Start

X
fair-roseOP•6mo ago
@Manuel Schiller @Tanner Linsley Made a recording for you guys to see what i mean.
https://github.com/Arinji2/vocab-thing/tree/tanstack-testing
thats the code of the video
GitHub
GitHub - Arinji2/vocab-thing at tanstack-testing
Contribute to Arinji2/vocab-thing development by creating an account on GitHub.
fair-roseOP•6mo ago
Also why does adding a persisting setup delete the devtools? I liked them a lot lol
absent-sapphire•6mo ago
what did delete the devtools?
fair-roseOP•6mo ago
Adding the persistQueryClient
Soo uhh any ideas @Manuel Schiller
absent-sapphire•6mo ago
about what?
fair-roseOP•6mo ago
doing something like this