Using tanstack query for caching in rest APIs #9394
Answered
by
TkDodo
RobinVdBroeck
asked this question in
Q&A
-
Hello, I wonder if anyone ever used a tanstack query like system for caching (but mostly cache invalidation) in rest apis. Let's say I've got a simple crud system:
The implementing code could than look somelike - in psuedocode:
Does this have any gotchas I should be aware of? |
Beta Was this translation helpful? Give feedback.
Answered by
TkDodo
Jul 15, 2025
Replies: 1 comment 2 replies
-
you can’t |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can definitely use react-query for caching on the server, but note that it doesn’t persist per anywhere default (it’s in memory only), so it doesn’t really compare with redis. It’s also not distributed and probably not optimized specifically for this use-case.
What you can do is combine a QueryClient with persistence and a server storage solution like redis:
QueryClient
dehydrate
by reading from e.g. redishydrate
and write it to redis.then, when the next request comes in, it will restore from redis and you’d basically have a f…