Why aren't my new cache rules taking effect!


One thing that tripped me up was when I created a new ‘Cache Setting’ in the ‘Settings’ tab of the Fastly app to force the TTL and Grace settings. I had other settings and rules that set headers that I had created previously but what I didn’t realise was that creating a Cache setting with action ‘CACHE’ and no condition (ie it would apply to all requests) would create the following VCL:

# priority: 0
# Here's my Test Cache Header. Notice that it's priority '0'
# so it's been put before everything else
set beresp.ttl = 60s;
set beresp.grace = 61s;

# and here's my poor other header that will never execute. 
# It was set at the default of priority 10
# Header rewrite CORS : 10
set beresp.http.Access-Control-Allow-Origin = "*";

So, what happened was I had set the ‘Action’ of the cache setting to ‘CACHE’ rather than ‘N/A’ which was what it should have been.

So beware! If you want your Cache settings to play nicely with others and it must be a CACHE action make sure there’s a condition. Otherwise change the action to ‘N/A’.