Next.js Discord

Discord Forum

trying to understand server side and fetch and cache

Answered
Asian black bear posted this in #help-forum
Open in Discord
Avatar
Asian black bearOP
i have a Page that is pretty much
import { getProjects } from './api/projects/service';

// `app/page.tsx` is the UI for the `/` URL
export default async function Page() {
  const projects = await getProjects();
  return <html>...</html>


and getProjects is just a fetch call that looks similar to the example on the docs page here (https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)

i do have it set with this option fetch('https://...', { next: { revalidate: 3600 } }) to supposedly make it revalidate every 3600 seconds max

when i build my app it tells me that all the pages are Static
Route (app)                                      Size     First Load JS
┌ ○ /                                            33.3 kB         112 kB
[...]
â—‹  (Static)  automatically rendered as static HTML (uses no initial props)

because they use no intial props

and i then deploy this via vercel

it seems that it will only ever be "static" indeed and use the fetched value at build time, and never "refetch" after the hour has passed, how do i make it be server side and still refetch after the cache timeout has passed ? is this a thing that is possible?
Answered by Asian black bear
doing some tests setting the revalidate value at 1 does seem to work actually even though the pages are marked as "static"
im guessing im getting cached by the actual api responding the data maybe, maybe some ip based cache or something i have no clue
View full answer

4 Replies

Avatar
Asian black bearOP
doing some tests setting the revalidate value at 1 does seem to work actually even though the pages are marked as "static"
im guessing im getting cached by the actual api responding the data maybe, maybe some ip based cache or something i have no clue
Answer
Avatar
Alfonsus Ardani
Static Routes are by default set to statically rendered pages. This means that the route will be build only once per given moment of time. It is stored in the Full Router cache forever or until revalidation
It does not refetch when the timer is up. What i does is it marks the route as invalidated such that it will trigger background revalidation on subsequent request
This would just mean you are doing background revalidation at every request which is may or may not be suitable depending on your case.