Next.js Discord

Discord Forum

Where is Edge cache located?

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Avatar
Transvaal lionOP
Hey, we have a Next.js project hosted on Vercel.

Our middleware is running with the edge runtime, and the serverless functions are configured with the node runtime, running in Paris (CDG).

We are trying to configure the "full route cache" naively by simply adding the Cache-Control header on responses for instance with the recommended settings in next.config.js.

        headers: [
          {
            key: 'Cache-Control',
            value: 'max-age=0, s-maxage=86400',
          },


When trying to load my website (the full page reload), I see the following response headers in the browser:

x-vercel-id=fra1::cdg1::xhhrb-1729770361079-47423ce32df2
x-vercel-cache=HIT


Until now, I think this is coherent. I am close to Frankfurt, so I am hitting the middleware in "fra1", and the request is forwarded to the "cdg1" region where my serverless functions are supposed to be invoked.

But now I try to understand the cache. From what I see, having x-vercel-cache to HIT means that the page/route was retrieved from the cache. Again, this seems accurate as I added the Cache-Control directive.

Our functions are configured in Vercel on "performance" mode with 1.7 vCPUs and 3 GB memory.

However, the page loads sometimes very slowly. It varies from 60ms to 600ms, but always returns x-vercel-cache to HIT.

My question is: do you know where the cache is actually located? Is it in the same region as the middleware (close to the user), or is it in the region of the serverless functions?
Image

1 Reply

Avatar
Transvaal lionOP
Some documentation pages say the latter (https://vercel.com/docs/edge-network/caching#cache-control-options), but I have seen other next.js sites with the same configuration (same middleware and serverless runtimes) as mine which returns x-vercel-id to fra1::8ngq5-1729771449258-f8b004d53a29 . You can see that only "fra1" (where middleware is located) is logged. Also, it seems to be generally faster.

So are there different kinds of cache with some located at the middleware region and others at the serverless region? I am struggling to understand infrastructure and cache in next.js plus Vercel and help would be greatly appreciated!