You can't cache a component that needs to access cookies since its output would change for every request
The idiomatic solution here is to use Partial Prerendering, which allows pre-rendering layouts while still rendering certain components dynamically, and then to move the code that accesses cookies down into a component that is wrapped in Suspense
Users will initially be served a cached layout with the suspense boundary showing its fallback, and then the fallback will be replaced with the dynamic data once the cookies have been read
https://nextjs.org/docs/app/getting-started/partial-prerendering#dynamic-apis