ํฐ์คํ ๋ฆฌ ๋ทฐ
HTTP ์๋ฒฝ๊ฐ์ด๋ 7์ฅ Cache๋ฅผ ์ฝ๊ณ ์ ๋ฆฌํ ๊ธ์ ๋๋ค.
์ฐ์ Web Caching ์ด๋?
HTTP ํต์ ์ response์ body ์ ํด๋นํ๋ content document๋ฅผ
๋ก์ปฌ์ ์ ์ฅํ์ฌ ํด๋น document์ ์์ฒญ์ด ์์๋ ์๋ฒ์์ response๋ก ๋ฐ๋ ๋์ ๋ก์ปฌ์์ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ์ ๋๋ค.
์ฐ์ web cache์ ๋ํด ์ตํ ๊ด์ 3๊ฐ์ง์ ๋๋ค.
- ์บ์ฑ์ด ์ด๋ป๊ฒ ์ฑ๋ฅ์ ํฅ์ ์ํค๋์ง
- ์ด๋ป๊ฒ ์ต์ ์ํ์ ์บ์๋ฅผ ์ ์งํ๋์ง
- ์บ์ฑ๊ณผ ์๋ฒ๊ฐ์ ์ด์ฉ ๋ฐฉ๋ฒ
์ด ๊ด์ ์ ์ ์งํ๋ฉด์ ๊ธ์ ์ฝ์ด์ฃผ์๋ฉด ๋์์ด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
์บ์ฑ ํ์๋์ ์ฅ์ 3๊ฐ์ง ์ ๋๋ค.
- ์ค๋ณต๋ ๋ฐ์ดํฐ๋ฅผ ๋ ๋ณด๋ด์ง ์์๋ ๋จ
- ๋คํธ์ํฌ ๋ณ๋ชฉํ์ ๊ฐ์
- ๋น ๋ฅธ ๋ก๋
์ด ์ธ๊ฐ์ง๊ฐ ๋ค ๊ฐ์ ๋งฅ๋ฝ์ด๊ธฐ๋ ํ๋ฐ.
์์ฒญ์ ๋ํ ์๋ต ํ์๋ฅผ ์ค์ด๋ฉด์ ๋ํ๋๋ ํจ๊ณผ๋ค์
๋๋ค.
์ฒซ๋ฒ์งธ, ๋๋ฒ์งธ ์ฅ์ ์ผ๋ก ์๋ฒ ์ธก์์ ๋๋ ํต์ ๋น์ฉ์ ์ค์ผ ์ ์์ต๋๋ค.
์ธ๋ฒ์งธ๋ ํด๋ผ์ด์ธํธ์ ์ธก๋ฉด์ธ๋ฐ,
์๋ต ๋ฐ๋์ ์ฝํ
์ธ ์์ ๊ฐ์ ๋ฐ๋ ๋์ ๋ก์ปฌ์์ ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์์ ๋น ๋ฅธ ํ์ด์ง ๋ก๋๊ฐ ๊ฐ๋ฅํฉ๋๋ค.
์บ์ฑ์ ์์๋ก 2๊ฐ์ง๊ฐ ์์ต๋๋ค.
ํ๋๋ ๋ง์ ์ฌ๋๋ค์ด ๋์์ ๋ชฐ๋ ธ์๋
๊ฐ์ ์๋ต์ ๋ฐ๋ณตํด์ ์ฃผ๊ฒ ๋๋๋ฐ ๊ทธ๊ฑธ ์บ์๋ก ์ฒ๋ฆฌํ๋ฉด ๋ง์ ์ฌ๋์ด ๋ชฐ๋ ค๋ ์บ์๋ก ์๋ฒ ๋ถํ๋ฅผ ์ค์ผ ์ ์์ต๋๋ค.
๋๋ฒ์งธ๋ ์๋ฒ์ ํด๋ผ์ด์ธํธ์ ๋ฌผ๋ฆฌ์ ๊ฑฐ๋ฆฌ๊ฐ ๋ฉ๋ ๊ทธ ์ฌ์ด์ ์บ์๋ฅผ ์ ์ฅํ ์ ์๋ ์ฅ์น (eg. CDN)๋ฅผ ๋ฐฐ์นํ์ฌ ์บ์๋ฅผ ๊ฑฐ๊ธฐ ์ ์ฅํ๋ฉด ๋ฌผ๋ฆฌ์ ๊ฑฐ๋ฆฌ๊ฐ ์ค์ด๋ค์ด ํต์ ์๊ฐ์ ์ค์ผ ์ ์์ต๋๋ค.
์บ์ํ์๋ ์๊ธธ ์ ์๋ ๋ฌธ์ ์ ๊ณผ ํด๊ฒฐ๋ฐฉ์์ ๋๋ค.
- ์บ์ฑํ ๋ฐ์ดํฐ๊ฐ ์ต์ ๋ฐ์ดํฐ๊ฐ ์๋ ๊ฒฝ์ฐ → Revalidations๋ก ์ ํจ์ฑ์ ๊ฒ์ฌํฉ๋๋ค.
- ๋ณ๊ฒฝ์ฌํญ ์์ผ๋ฉด 304 Not Modified response
- ๋ณ๊ฒฝ์ฌํญ ์์ผ๋ฉด 200 + full content
- ์ญ์ ๋์ผ๋ฉด 404
- ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ์บ์ฑ ํ ์์๊ณ
- ๋ฎ์ ์บ์ hit rate์ด ์์ต๋๋ค → 2, 3๋ฒ ๋ชจ๋ ์ฐ๊ด์ฑ, ์ธ๊ธฐ ๋์ ๋ฐ์ดํฐ๋ค์ ์บ์์ ์ ์ฅํจ์ผ๋ก์จ ํด๊ฒฐ๊ฐ๋ฅํฉ๋๋ค.
- ์บ์ hit์ response๊ณผ ์๋ฒ์ response ๋ชจ๋ ์๋ต์ฝ๋ 200 → ์๋ต ํค๋์ date๊ฐ or Age๋ก ๊ตฌ๋ถ ๊ฐ๋ฅํฉ๋๋ค.
* ์บ์ hit๋ ์บ์์ ์ํ๊ฐ freshํ์ฌ ์ฌ์ฉํ ์ ์๋ ๊ฒฝ์ฐ๋ฅผ ๋งํจ.
์บ์ฑ์ ํ๋ 6๋จ๊ณ์ ๋๋ค.
- client์์ ๋ณด๋ด๋ HTTP request message๋ฅผ ์ฝ์ต๋๋ค.
- message๋ฅผ parsingํฉ๋๋ค.
- ์บ์๊ฐ ์๋์ง ํ์ธํฉ๋๋ค.
- ์บ์์ fresh๋ฅผ ํ์ธํฉ๋๋ค (์ ํจํ ๊ฒฝ์ฐ) → ์ ํจ์ฑ ๊ฒ์ฌ ๋ฐฉ๋ฒ 4-2
- response๋ฅผ ์์ฑํ๊ณ ์๋ก์ด ํค๋๊ฐ์ ์ถ๊ฐํ์ฌ reponse๋ก ๋ณด๋ด์ค๋๋ค. ์๋๋ cache ๊ด๋ จํ์ฌ ์ถ๊ฐ๋ ์ ์๋ response header์ ์์ฑ๊ฐ์
๋๋ค.
- Age → ์บ์ ๋ฐ๊ธ ์ดํ ์ด๊ณผ ์๊ฐ (์ด๋จ์)
- Expires headers → ๋ง๋ฃ ์๊ฐ
- Cache-Control ์บ์ ์ ์ด ๊ธฐ๋ฅ
- private public
- private: ๊ฐ์ธ ์ ์ฉ ์บ์
- public: ๊ณต์ ์ ์ฉ ์บ์ (proxy cache)
- Max-Age ์๋ต ํค๋
- Cache-Control: max-age=3600 → ์บ์๋ฐ๊ธ ์ดํ 3600์ด๊ฐ ์ง๋์ ์บ์๋ฅผ ์์ฒญํ๊ฒ ๋ ๊ฒฝ์ฐ ์ฌ๊ฒ์ฆํด์ผํจ.
- Cache-Control: s-maxage=3600 (only public caches) → ํ๋ก์ ์บ์์์ ์ฌ์ฉํ๋ ์ฉ๋
- no-store
- Cache-Control: no-store
- ๋ก์ปฌ์ ์ ์ฅํ์ง ์๋๋ค๋ ๋ป
- no-cache
- Cache-Control: no-cache
- ์บ์๋ ์ ์ฅ. but ๋งค๋ฒ ์ฌ๊ฒ์ฆ, max-age=0 ๊ณผ ๊ฐ์ ์๋ฏธ → ๊ณ์ ์๋ต ์์ฒญ
- must-revalidate
- Cache-Control: must-revalidate
- fresh check๋ฅผ ๋ฌด์ํ๊ณ ์ฌ๊ฒ์ฆ ์๋
- stale-while-revalidate=<seconds>
- Age๊ฐ ํด๋น ์๊ฐ์ ์ด๊ณผํ์ง ์์ ๊ฒฝ์ฐ ์ผ๋จ ์บ์ ๋ฐ์ดํฐ๋ฅผ ๋์ฐ๊ณ , ๋น๋๊ธฐ์ ์ผ๋ก ์บ์ ๊ฐ์ ๊ฐฑ์ ํฉ๋๋ค.
- private public
4-2. ์๋ฒ ์ฌ๊ฒ์ฆ (Server Revalidation) : ์ ํจ ๊ธฐ๊ฐ ๋ง๋ฃ ์ฌ๋ถ ํ์ธ
-
- ์กฐ๊ฑด๋ถ ์์ฒญ conditinal GET : ์บ์๊ฐ hit ํ์ ๊ฒฝ์ฐ ์๋ต์ผ๋ก ํค๋๋ง ๋ฐ๊ธฐ ๋๋ฌธ์ ๋น์ฉ์ด ๋ฎ์.
- If-Modified-Since<date> (IMS) : Last-Modified(๊ธฐ์กด ์๋ต ํค๋)๊ฐ ์ดํ ๋ณ๊ฒฝ ์ฌํญ์ด ์กด์ฌํ๋์ง ํ์ธ
- If-None-Match<tags> : documnet serial number ๊ฐ ๋น๊ต
์บ์ฑ ์ ์ฑ
https://web.dev/http-cache/#defining-optimal-cache-control-policy
์ถ๊ฐ์ ์ธ Cache-Control request directives (์บ์ ์ปจํธ๋กค ์์ฒญ ์ง์์)
https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/Cache-Control
Referense
https://toss.tech/article/smart-web-service-cache
https://www.rfc-editor.org/rfc/rfc5861
- Total
- Today
- Yesterday
- llm csv
- swift excel read
- rag ๊ธฐ๋ฐ llm
- concurrency pagination
- swift queryitem encode
- swift ์๊ฐ
- filemanager excel read
- llm pdf rag
- rag llm pdf
- swift ๋คํธ์ํฌ ๋ชจ๋ํ
- swift urlsession refactoring
- ๋น๋๊ธฐ ํ์ด์ง swift
- chatgpt rag llm
- ๋ ๋์ธ์ด
- swift network module
- ๋ ๋์ธ์ด ์ดํ
- swift ์์ ์ฝ๊ธฐ
- ๋น๋๊ธฐ ๋ฆฌ์คํธ swift
- ๊ณต๋ถ ํ์ด๋จธ ์ดํ
- ์๋์ํํธ ๋ ์ด์ธ์ด
- swift urlsession ๊ณตํตํ
- swift filemanager get excel
- swift network ๊ณตํตํ
- swift network refactoring
- swift get excel
- readysay
- swift urlcomponent encode
- rag ๊ธฐ๋ฐ llm ์ฑ๋ด
- swift filemanager excel
- swift ์์ ๊ฐ์ ธ์ค๊ธฐ
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |