Just keep coding ...

[Next.js] (8) - Data Cache

2024. 11. 12. 06:41ใ†front-end/Next.js

728x90

๐Ÿ‘‰ Data Cache

  • fetch ๋ฉ”์„œ๋“œ๋ฅผ ํ™œ์šฉํ•ด ๋ถˆ๋Ÿฌ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ Next์„œ๋ฒ„์—์„œ ๋ณด๊ด€ํ•˜๋Š” ๊ธฐ๋Šฅ
  • ์˜๊ตฌ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ ๋ณด๊ด€, ํŠน์ • ์‹œ๊ฐ„์„ ์ฃผ๊ธฐ๋กœ ๊ฐฑ์‹  ์‹œํ‚ค๋Š” ๊ฒƒ ๊ฐ€๋Šฅ
  • ๋ถˆ ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ ์š”์ฒญ ์ˆ˜๋ฅผ ์ค„์—ฌ์„œ ์›น ์„œ๋น„์Šค์˜ ์„ฑ๋Šฅ ํฌ๊ฒŒ ๊ฐœ์„  ๊ฐ€๋Šฅ
const response = await fetch('/api',{ cache: "force-cache" });
//์š”์ฒญ์˜ ๊ฒฐ๊ณผ๋ฅผ ์บ์‹ฑํ•จ, ํ•œ ๋ฒˆ๋งŒ ๋ถˆ๋Ÿฌ์˜ด
//next.js ์—์„œ fetch ๋ผ๋Š” ๋ฉ”์„œ๋“œ๋งŒ ์‚ฌ์šฉํ•ด์•ผํ•จ

const response = await fetch('/api',{ cache: "no-store" });
//๋ฐ์ดํ„ฐ ํŽ˜์นญ์˜ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•˜์ง€ ์•Š๋Š” ์˜ต์…˜
//์บ์‹ฑ์„ ์•„์˜ˆ ํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •ํ•˜๋Š” ์˜ต์…˜

const response = await fetch('/api',{ next: { revalidate: 3 } });
//Page Router์˜ ISR ๊ธฐ๋Šฅ๊ณผ ์œ ์‚ฌํ•จ
//ํŠน์ • ์‹œ๊ฐ„์„ ์ฃผ๊ธฐ๋กœ ์บ์‹œ๋ฅผ ์—…๋ฐ์ดํŠธ

const response = await fetch('/api',{ next: { tag: ['a'] } });
//On-Demand Revalidate
//์š”์ฒญ์ด ๋“ค์–ด์™”์„ ๋•Œ ๋ฐ์ดํ„ฐ๋ฅผ ์ตœ์‹ ํ™” ํ•จ

no-store
force-cache
revalidate

 

  • next ํด์ €์— ์ €์žฅ๋œ cache ๋ฐ์ดํ„ฐ ํ™•์ธ ๊ฐ€๋Šฅ

 

  • nextConfig ํŒŒ์ผ์— logging, fetches ๊ฐ’์„ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ์„œ๋ฒ„ ๋กœ๊น…๊ฐ€๋Šฅ (ex: cahce skip)
const nextConfig: NextConfig = {
  /* config options here */
  logging: {
    fetches: {
      fullUrl: true,
    },
  },
}

 

 

 


์ถœ์ฒ˜: https://www.inflearn.com/course/%ED%95%9C%EC%9E%85-%ED%81%AC%EA%B8%B0-nextjs/dashboard

 

ํ•œ ์ž… ํฌ๊ธฐ๋กœ ์ž˜๋ผ๋จน๋Š” Next.js(15+) ๊ฐ•์˜ | ์ด์ •ํ™˜ Winterlood - ์ธํ”„๋Ÿฐ

์ด์ •ํ™˜ Winterlood | ํ•œ์ž… ์‹œ๋ฆฌ์ฆˆ์˜ 3๋ฒˆ์งธ ์ž‘ํ’ˆ! ์„ธ์ƒ์—์„œ ๊ฐ€์žฅ ์นœ์ ˆํ•˜๊ณ  ๋””ํ…Œ์ผ ํ•œ Next.js(15+)๊ฐ•์˜ ์ž…๋‹ˆ๋‹ค. App Router ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ Page Router๊นŒ์ง€ ํ”„๋กœ์ ํŠธ๋ฅผ ํ†ตํ•ด ์‚ดํŽด๋ด…๋‹ˆ๋‹ค., [์ž„๋ฒ ๋”ฉ ์˜์ƒ]ํ•œ ์ž… ํฌ๊ธฐ

www.inflearn.com

 

728x90