Weird cache behavior

I created a new t3 app with app router and trpc. Then I moved CrudShowCase (including the get posts part) to a new route. I realized a weird behavior after adding artificial delay to the get posts api. 1. On initial visit - fetch data from source and takes a while 2. On subsequent visits < 30s: instant page load due to cache 3. On first visit after 30s - fetch data from source and takes a while 4. All visits from here on - fetch data from source and takes a while. The discrepancy/unexpected outcome is 4. I thought 4 should be the same as 2, in that the cache is reset to the 30s timer and the user would get instant page loads again. But that is not the case. Can someone confirm this is expected or non-expected behavior?
10 Replies
deforestor
deforestor9mo ago
Just to confirm, the data didn't change at all, did it?
shikishikichangchang
Not at all I also noticed using the browser’s back and forward buttons gives instant page loads
shikishikichangchang
Just tested on vercel’s demo page and it’s the same behavior https://demo.vercel.store
Acme Store
High-performance ecommerce store built with Next.js, Vercel, and Shopify.
shikishikichangchang
I also realixed if I use prefetch false for the Link that navigates to the page, and build the app then perform the navigations steps above, it works now - in that it caches the page for 30s everytime (not just the first time) uploadthing has the same behavior
shikishikichangchang
same behavior on https://skateshop.sadmn.com/ as well
Skateshop
Skateshop
An open source e-commerce skateshop build with everything new in Next.js.
shikishikichangchang
Apparently it's expected behavior https://github.com/vercel/next.js/pull/48383
GitHub
app-router: new client-side cache semantics by feedthejim · Pull Re...
This PR implements new cache semantics for the app router on the client. Context Currently, on the App Router, every Link navigation is prefetched and kept forever in the cache. This means that onc...
shikishikichangchang
who wouldve thought prefetch changes the behavior of caching
deforestor
deforestor9mo ago
Very interesting research I'll keep this saved Thank you!
shikishikichangchang
Clarified a lot of confusion for myself after thorough research. wanted to share it with you @ed
Want results from more Discord servers?
Add your server