Skip to content

Apollo Client's Cache

Ahrim Yang edited this page Nov 30, 2020 · 4 revisions

์ž‘์„ฑ์ž: J166 ์ดํ—Œ์ค€

Apollo Client๋Š” ์–ด๋–ป๊ฒŒ ์บ์‹ฑ์„ํ•˜๊ณ , cache๋ฅผ ์–ด๋””์— ์ €์žฅํ•˜๋Š”๊ฐ€?

์•„ํด๋กœํด๋ผ์ด์–ธํŠธ๋Š” GraphQL ์ฟผ๋ฆฌ์˜ ๊ฒฐ๊ณผ๋ฅผ normalize(์ •๊ทœํ™”)ํ•˜์—ฌ in-memory cache์— ์ €์žฅํ•œ๋‹ค. ์ด๋กœ์จ, ํด๋ผ์ด์–ธํŠธ๋Š” ๊ฐ™์€ ์ •๋ณด๋ฅผ ์š”์ฒญํ•˜๋Š” ์ดํ›„์˜ ์ฟผ๋ฆฌ์— ๋Œ€ํ•˜์—ฌ ๋ถˆํ•„์š”ํ•œ ๋„คํŠธ์›Œํฌ ์š”์ฒญ์„ ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. (Inmemory Cache ํด๋ž˜์Šค๋Š” @apollo/client ํŒจํ‚ค์ง€์—์„œ ์ œ๊ณต๋œ๋‹ค.)

  • Data Normalization InMemoryCache๋Š” ๋‚ด๋ถ€์˜ ๋ฐ์ดํ„ฐ ์ €์žฅ์†Œ์— ์ €์žฅํ•˜๊ธฐ์ „์— ์‘๋‹ต๊ฐ’์„ ์ •๊ทœํ™”ํ•œ๋‹ค. ์ •๊ทœํ™”๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ ˆ์ฐจ๋ฅผ ๊ฑฐ์นœ๋‹ค

    1. ์‘๋‹ต๊ฐ’์˜ ๊ตฌ๋ถ„๊ฐ€๋Šฅํ•œ ๊ฐ’์„ ์‚ฌ์šฉํ•˜์—ฌ ID๋ฅผ ์ƒ์„ฑํ•œ๋‹ค
    2. ์‘๋‹ต๊ฐ’๊ณผ ID์˜ 2์ฐจ์› table์„ ๋งŒ๋“ ๋‹ค
    3. ID๊ฐ€ ๊ฐ™์„ ๋•Œ ๋งˆ๋‹ค(์‘๋‹ต๊ฐ’์˜ ๊ตฌ๋ถ„๊ฐ€๋Šฅํ•œ ๊ฐ’์ด ๊ฐ™์„ ๋•Œ) ํ•ด๋‹น ID์— mergeํ•œ๋‹ค.

์บ์‹ฑ ๊ด€๋ จ ๊ณต์‹๋ฌธ์„œ

Clone this wiki locally