X
Xata•17mo ago
Kaligraphy

Any caching strategy when using Xata

Any caching strategy when using Xata with Nextjs?
11 Replies
kostas
kostas•17mo ago
There is an experimental caching feature within the SDK client itself, an example of which you can find in the first code block here: https://xata.io/docs/concepts/how-it-works#edge-caching-and-edge-functions-private-beta
return await xata.db.products.sort('popularity', 'desc').getMany({
cache: 10 * 60 * 1000 // TTL
});
return await xata.db.products.sort('popularity', 'desc').getMany({
cache: 10 * 60 * 1000 // TTL
});
This works at the client level, each client instantiation having its own cache. It is a simple approach, in anticipation of our new Edge Caching layer that provides a global edge cache (first item in our roadmap here: https://xata.io/roadmap). The new Edge caching should available for early access in the coming weeks so watch this space!
How Xata works
Xata paves the way for scalability, efficient data operations, and accelerated app development
Kaligraphy
KaligraphyOP•17mo ago
this helps greatly, I'm seeing multiple requests to the DB, especially for stale data, and I'll like to limit that It works! Not so experimental after all.
kostas
kostas•17mo ago
Thanks for giving it a try and glad to read it helps! There might just be some rough edges (like this example here https://github.com/xataio/client-ts/issues/907) but the upcoming edge cache will polish those.
Kaligraphy
KaligraphyOP•17mo ago
okay, i made a mistake i think the cache miss I'm getting now is from nextjs, how can I definitely confirm that it's cached? never mind, it working fine 😅 Apologies for the confusion
kostas
kostas•17mo ago
Ah ok great. I don't think there is a way to inspect the experimental cache at this point. The only way I can think of to check if a result is served from the cache or not is to update its value (from the UI) and see what you get back after the update.
Kaligraphy
KaligraphyOP•17mo ago
the rough check i am using is simply commenting and uncommenting the cache option
kostas
kostas•17mo ago
that definitely works as well 🙂
Kaligraphy
KaligraphyOP•17mo ago
Okay, the cache definitely works, regardless of what Nextjs is reporting. It looks it doesn't live very long in the dev server. Ill try in the prod and get back to you
kostas
kostas•17mo ago
Sounds good, it should help trim down some response times 🙂
Kaligraphy
KaligraphyOP•17mo ago
I am happy to report that it works as expected in prod after 10 mins TTL
kostas
kostas•17mo ago
Really happy to read this. There will be major improvements on this front soon, but it is great that the local cache is helpful until then.
Want results from more Discord servers?
Add your server