I have about 50k .jpg images stored in S3 and I have configured CloudFront to deliver those through the CDN. My cache hit rate over the past month is only about 16% on average. Under behavour, I have configured the CDN to have a Min TTL of 1 day (86400 seconds), a Max TTL of 1 year (31536000 seconds) and a default TTL of 1 day. From S3, each of my images responds with the following Cache-control
header:
Cache-Control: public, max-age=31536000
Here are the other response headers from the Origin Server (S3).
Accept-Ranges: bytes
Cache-Control: public, max-age=31536000
Content-Length: 22420
Content-Type: image/jpeg
Date: Fri, 24 Jan 2020 00:50:55 GMT
ETag: "75b4b9e2693058f143df962efe7305dd"
Last-Modified: Wed, 04 Dec 2019 15:20:08 GMT
Server: AmazonS3
x-amz-id-2: rpJdSKKlDkGqxIQrY2Lu887IYuwJPeoZQ40c8CQa11ZEjfuUdLtG19m/frrOeXtDK3gByc6pOlc=
x-amz-request-id: E68021E10D5DB297
If I wait a while (30 minutes) and request this image again, I get a cache miss. Immediately after, I can request the image again and get a cache hit. I can get a cache hit for subsequent calls as long as I don't leave the object untouched for any period of time. I don't understand why the Min TTL value that I set isn't keeping the images in cache longer. I do understand that Amazon will remove images from the Cache that aren't accessed as frequently as others, but this is causing my cache miss rate to become quite high. How can this issue be resolved?
Thanks in advance.
UPDATE
Below I have posted my behavior configs:
Here are my Cloudfront response headers:
accept-ranges: bytes
age: 53
cache-control: public, max-age=31536000
content-length: 6707
content-type: image/jpeg
date: Sat, 25 Jan 2020 00:06:47 GMT
etag: "b511907ae7c3c2299d1e3022f6253f2f"
last-modified: Fri, 11 Oct 2019 05:08:40 GMT
server: AmazonS3
status: 200
via: 1.1 15e6db7015a157ee446cfd6592fca1b3.cloudfront.net (CloudFront)
x-amz-cf-id: AFAkhVgvzj9NjiEFz-222m0uJE5G8B5R2bE06K5Dnsn3Rdz2NqEkdw==
x-amz-cf-pop: ATL52-C1
x-cache: Hit from cloudfront
Wait 5 minutes and request the same image again. Here are the headers for that response.
accept-ranges: bytes
cache-control: public, max-age=31536000
content-length: 6707
content-type: image/jpeg
date: Sat, 25 Jan 2020 00:12:01 GMT
etag: "b511907ae7c3c2299d1e3022f6253f2f"
last-modified: Fri, 11 Oct 2019 05:08:40 GMT
server: AmazonS3
status: 200
via: 1.1 e11ff5647028a0e212255f92e5436d8b.cloudfront.net (CloudFront)
x-amz-cf-id: a7ha0wB_cyWO77fmoXNtxiMLOX-3ufFU0McgpWwkoYpzFlCMB6CmCw==
x-amz-cf-pop: DFW3-C1
x-cache: Miss from cloudfront
I am noticing that each time I get a miss the x-amz-cf-pop
header changes.