나는 서버컴포넌트에서 next캐시를 사용하고있었는데 캐시가 적용되지않고 계속 불러와지는 일이 발생했다.
찾아보니 next에서 개발모드(dev)에서는 계속 확인해야하니 캐시를 무시하고 보여지고, 실제 배포를하면(production) 캐시가 적용된다고 나와있었다.
그러나 배포후까지 기다릴수도 없고, 배포를 계속 하면서 캐시여부를 확인하기에는 너무 리소스가 많이들었다.
그래서 로컬에서도 production환경일때 확인할수있는 방법을 찾아보았다.
const eng_name = await getCenterName();
const response = await fetch(`${process.env.SERVER_API_HOST}/config?eng_name=${eng_name}`, {
next: { revalidate: 3600 }, // 1시간
cache: 'force-cache',
});
const cachedConfig = (await response.json()) as Config;
nextjs를 로컬버전에서 빌드한다. npn run build
빌드하면 자체적으로 배포할 수 있는 폴더가 생성된다. standalone
다음 명령어를 수행하여, 폴더에 수동으로 복사 한다.
cp -r public .next/standalone/ && cp -r .next/static .next/standalone/.next/
node .next/standalone/server.js
https://nextjs.org/docs/pages/api-reference/config/next-config-js/output