AWS CloudFront Cache Key ์๋ฒฝ ๊ฐ์ด๋
Cache Key ๊ฐ๋ ์ดํดํ๊ธฐ
๊ธฐ๋ณธ ๊ฐ๋
Cache Key๋ ๋ง์น ๋์๊ด์ ์ฑ ๋ถ๋ฅ ๋ฒํธ์ ๊ฐ๋ค. ๋์๊ด์์ ์ฑ ์ ์ฐพ์ ๋ ๋ถ๋ฅ ๋ฒํธ๋ฅผ ์ฌ์ฉํ๋ฏ์ด, CloudFront๋ Cache Key๋ฅผ ์ฌ์ฉํ์ฌ ์บ์๋ ์ฝํ ์ธ ๋ฅผ ์๋ณํ๊ณ ๊ฒ์ํ๋ค.
๊ธฐ๋ณธ ๊ตฌ์กฐ
graph LR A[์์ฒญ] --> B[Cache Key ์์ฑ] B --> C{์บ์ ํ์ธ} C -->|Hit| D[์บ์๋ ์๋ต ๋ฐํ] C -->|Miss| E[์ค๋ฆฌ์ง์์ ์ฝํ ์ธ ๊ฐ์ ธ์ค๊ธฐ] E --> F[์บ์ ์ ์ฅ] F --> D
Cache Key ๊ตฌ์ฑ ์์
1. ๊ธฐ๋ณธ ๊ตฌ์ฑ ์์
- URL ๊ฒฝ๋ก
- ํธ์คํธ ์ด๋ฆ
- ํ๋กํ ์ฝ(HTTP/HTTPS)
2. ์ ํ์ ๊ตฌ์ฑ ์์
- ์ฟผ๋ฆฌ ๋ฌธ์์ด
- HTTP ํค๋
- ์ฟ ํค
- ์ฌ์ฉ์ ์ ์ ๊ฐ
Cache Key ์ค์ ์์
CloudFront ์ค์ ์์
๊ธฐ๋ณธ ์ค์ (๋ชจ๋ ์ฟผ๋ฆฌ ๋ฌธ์์ด ํฌํจ)
{
"DistributionConfig": {
"CacheBehaviors": {
"DefaultCacheBehavior": {
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6"
}
}
}
}ํน์ ์ฟผ๋ฆฌ ๋ฌธ์์ด๋ง ํฌํจ
{
"CachePolicy": {
"Name": "CustomQueryString",
"QueryStringsConfig": {
"QueryStringBehavior": "WHITELIST",
"QueryStrings": {
"Items": [
"size",
"color",
"response-content-disposition"
]
}
}
}
}์ค์ ์ฌ์ฉ ์ฌ๋ก
1. S3 ํ์ผ ๋ค์ด๋ก๋ ์ค์
์๋ชป๋ ์์
// Cache Key ์ค์ ์์ด S3 ํ์ผ ๋ค์ด๋ก๋ URL ์์ฑ
const fileUrl = 'https://cdn.example.com/files/document.pdf?response-content-disposition=attachment';์ฌ๋ฐ๋ฅธ ์์
// Cache Key์ response-content-disposition ํฌํจ
const fileUrl = 'https://cdn.example.com/files/document.pdf';
const downloadUrl = `${fileUrl}?response-content-disposition=${encodeURIComponent('attachment; filename="custom-name.pdf"')}`;2. ๋๋ฐ์ด์ค๋ณ ์ต์ ํ ์ค์
{
"CachePolicy": {
"Name": "DeviceOptimized",
"HeadersConfig": {
"HeaderBehavior": "WHITELIST",
"Headers": {
"Items": [
"CloudFront-Is-Mobile-Viewer",
"CloudFront-Is-Tablet-Viewer"
]
}
}
}
}์ฑ๋ฅ ์ต์ ํ
Cache Key ์ต์ ํ ์์น
graph TD A[Cache Key ๋ถ์] --> B{ํ์ ์์์ธ๊ฐ?} B -->|Yes| C[ํฌํจ] B -->|No| D[์ ์ธ] C --> E[์บ์ ์ ์ค๋ฅ ๋ชจ๋ํฐ๋ง] D --> E E --> F{์ฑ๋ฅ ๊ฐ์ ํ์?} F -->|Yes| A F -->|No| G[์๋ฃ]
์ต์ ํ ์ฒดํฌ๋ฆฌ์คํธ
- ๋ถํ์ํ ์ฟผ๋ฆฌ ๋ฌธ์์ด ์ ๊ฑฐ
- ํ์ ํค๋๋ง ํฌํจ
- ์ฟ ํค ์ฌ์ฉ ์ต์ํ
- ์บ์ ์ ์ค๋ฅ (Hit Ratio) ๋ชจ๋ํฐ๋ง
์ฃผ์์ฌํญ
๋ณด์ ๊ด๋ จ
- ๋ฏผ๊ฐํ ์ ๋ณด๋ฅผ Cache Key์ ํฌํจํ์ง ์๋๋ค
- Authorization ํค๋ ์ฌ์ฉ ์ ์ฃผ์
- HTTPS ์์ฒญ ์ฒ๋ฆฌ ๋ฐฉ์ ํ์ธ
์ฑ๋ฅ ๊ด๋ จ
- Cache Key ๋ณต์ก๋์ ์บ์ ์ ์ค๋ฅ ์ ๊ท ํ
- ๊ณผ๋ํ Cache Key ๋ณํ ์ฃผ์
- ์ ๊ธฐ์ ์ธ ์บ์ ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง
๋ชจ๋ํฐ๋ง ๋ฐ ๋๋ฒ๊น
CloudWatch ๋ฉํธ๋ฆญ
{
"Namespace": "AWS/CloudFront",
"MetricName": "CacheHitRate",
"Dimensions": [
{
"Name": "DistributionId",
"Value": "EDFDVBD6EXAMPLE"
}
]
}๊ฒฐ๋ก
ํจ์จ์ ์ธ Cache Key ์ค์ ์ CloudFront ์ฑ๋ฅ ์ต์ ํ์ ํต์ฌ์ด๋ค. ์บ์ ์ ์ค๋ฅ ์ ๋์ด๋ฉด์๋ ํ์ํ ์ฌ์ฉ์ ๋ง์ถคํ ์ฝํ ์ธ ๋ฅผ ์ ๊ณตํ ์ ์๋๋ก ์ ์คํ๊ฒ ์ค๊ณํด์ผ ํ๋ค. ํนํ S3์ ๊ฐ์ ์ค๋ฆฌ์ง ์๋ฒ์ ํจ๊ป ์ฌ์ฉํ ๋๋ ์ฟผ๋ฆฌ ๋ฌธ์์ด ํ๋ผ๋ฏธํฐ ์ฒ๋ฆฌ์ ์ฃผ์๋ฅผ ๊ธฐ์ธ์ฌ์ผ ํ๋ค.