Cache expiring too quickly


#1

Hi,

I’m using Fastly as a CDN in front of my Heroku application, and am seeing many requests that I expect to be cached make it through.

An example of this behavior is two requests to the URL:
https://nuu-acceptance-herokuapp-com.global.ssl.fastly.net/attachments/f092ff0398b3bace19fae21b17a22320c3da5428/store/fit/240/160/28515a2fa2e47b59f13b2044ea5b9a7c8c9587ceca7d7dfadb28f08730f7/file.jpg. Here are two responses from the requests, which occurred fifteen minutes apart:

RESPONSE 1:
----------
Strict-Transport-Security: max-age=31536000
Content-Encoding: gzip
X-Content-Type-Options: nosniff
Age: 0
Transfer-Encoding: chunked
X-Cache: MISS
X-Cache-Hits: 0
Content-Disposition: inline; filename="file.jpg"
Connection: keep-alive
Via: 1.1 vegur
Via: 1.1 varnish
X-Request-Id: bc766069-c2ca-4a66-ba88-a8d76da72e2d
X-Served-By: cache-sjc3124-SJC
X-Runtime: 3.711698
Last-Modified: Tue, 23 Jun 2015 18:44:27 GMT
Server: Cowboy
X-Timer: S1435085062.909546,VS0,VE4437
Date: Tue, 23 Jun 2015 18:44:27 GMT
Vary: Accept-Encoding
Content-Type: image/jpeg
Access-Control-Allow-Origin: *
Cache-Control: public, must-revalidate, max-age=31536000
Set-Cookie: __profilin=; path=/; max-age=0; expires=Thu, 01 Jan 1970 00:00:00 -0000; secure
Accept-Ranges: bytes
Expires: Wed, 22 Jun 2016 18:44:27 GMT
----------
RESPONSE 2:
----------
Strict-Transport-Security: max-age=31536000
Content-Encoding: gzip
X-Content-Type-Options: nosniff
Age: 0
Transfer-Encoding: chunked
X-Cache: MISS
X-Cache-Hits: 0
Content-Disposition: inline; filename="file.jpg"
Connection: keep-alive
Via: 1.1 vegur
Via: 1.1 varnish
X-Request-Id: 60ee54b0-9509-42c5-9b03-c0f5854c5524
X-Served-By: cache-sjc3135-SJC
X-Runtime: 0.251021
Last-Modified: Tue, 23 Jun 2015 18:57:44 GMT
Server: Cowboy
X-Timer: S1435085863.749442,VS0,VE560
Date: Tue, 23 Jun 2015 18:57:44 GMT
Vary: Accept-Encoding
Content-Type: image/jpeg
Access-Control-Allow-Origin: *
Cache-Control: public, must-revalidate, max-age=31536000
Accept-Ranges: bytes
Expires: Wed, 22 Jun 2016 18:57:44 GMT

Both are cache misses, even though I expect this content to be cached for a year. It also appears that the same Fastly cluster handled the request. Can anyone point me to what I might be doing wrong? I’m seeing this behavior across many files served by Fastly - fastly seems to serve the files intermittently, but there are cache misses much more often than I expect.

I’d appreciate any help that anyone could give me with this - thanks!


#2

Hey @tommy, it looks like there’s a Set-Cookie header in the first response, but not the second. Is that typical behavior?

On a side note, Fastly will never cache a response with a Set-Cookie header, as we don’t want to cache sessions or other user-specific content.


#3

@aspires thanks! I tracked down some cookies that were escaping, that I didn’t expect to be. I’ll make the necessary corrections and hopefully that fixes the problem!


#4

@aspires, I’m seeing the same behavior, with the issue with Set-Cookie fixed:

Here are response headers from requests to https://nuu-acceptance-herokuapp-com.global.ssl.fastly.net/attachments/efccc35acccbbce0d5ac3635226acdef62a4305f/store/fit/240/160/62a3a81436c6f407769d1364620ade57f47a4bac73aa5e5b0b122ba7ca1d/file.jpg, separated by only a few minutes:

RESPONSE 1:
----------
Strict-Transport-Security: max-age=31536000
Content-Encoding: gzip
X-Content-Type-Options: nosniff
Age: 0
Transfer-Encoding: chunked
X-Cache: MISS
X-Cache-Hits: 0
Content-Disposition: inline; filename="file.jpg"
Connection: keep-alive
Via: 1.1 vegur
Via: 1.1 varnish
X-Request-Id: 069c3e20-77e0-45de-b02c-5f0ad14a05c6
X-Served-By: cache-lax1431-LAX
X-Runtime: 0.284616
Last-Modified: Tue, 23 Jun 2015 22:28:30 GMT
Server: Cowboy
X-Timer: S1435098509.559662,VS0,VE583
Date: Tue, 23 Jun 2015 22:28:30 GMT
Vary: Accept-Encoding
Content-Type: image/jpeg
Access-Control-Allow-Origin: *
Cache-Control: public, must-revalidate, max-age=31536000
Accept-Ranges: bytes
Expires: Wed, 22 Jun 2016 22:28:30 GMT
----------
RESPONSE 2:
----------
Strict-Transport-Security: max-age=31536000
Content-Encoding: gzip
X-Content-Type-Options: nosniff
Age: 0
Transfer-Encoding: chunked
X-Cache: MISS
X-Cache-Hits: 0
Content-Disposition: inline; filename="file.jpg"
Connection: keep-alive
Via: 1.1 vegur
Via: 1.1 varnish
X-Request-Id: c1c2e0a3-7eeb-4b79-8278-c0f7de278064
X-Served-By: cache-lax1432-LAX
X-Runtime: 0.279486
Last-Modified: Tue, 23 Jun 2015 22:33:46 GMT
Server: Cowboy
X-Timer: S1435098825.623076,VS0,VE576
Date: Tue, 23 Jun 2015 22:33:46 GMT
Vary: Accept-Encoding
Content-Type: image/jpeg
Access-Control-Allow-Origin: *
Cache-Control: public, must-revalidate, max-age=31536000
Accept-Ranges: bytes
Expires: Wed, 22 Jun 2016 22:33:46 GMT    

For what it’s worth, the misses all seem to happen on lax machines. Is there anything else I should check?

EDIT

The following morning, with cookies completely removed, I am seeing close to a 30% miss rate on requests going through Fastly. I’m beginning to think that Fastly is just evicting some of my files from its cache. Is there any other explanation for what might be going on?


#5

hey @tommy sorry about the delay. My first assumption is that this may be due to cache warming – there’s usually a ramp period when all of your objects are getting pulled into cache where your hit rate starts low, but creeps up.

Did the 30% hit ratio change at all?