How do I configure my cache settings if I have no control over the headers and cookies being set by my origin (for example, using Netsuite)?


#1

If you do not have control over cache headers or cookies that are being set by your origin (for example, you are using NetSuite), you can still use Fastly to configure your caching.

By default, Fastly will not cache if there is a Set-Cookie. If your origin is setting a Set-Cookie on resources that you would like to cache, you can use Fastly to either strip out the Set-Cookie on those resources or override the default behavior and force those resources to cache.

Stripping out Set-Cookies:

Create a new Header rule under Configure -> Content -> Headers, and fill in the following fields:

Name: Remove Set Cookie (or your preferred name)
Type / Action: Cache / Delete
Destination: http.Set-Cookie

Then you would add a condition to that Header rule by clicking the gear icon on the right. When the modal pops up, create a new condition and fill out the following fields:

Name: Static Files Only (or your preferred name)
Apply If...: req.url ~ ".(png|jpg|css|js)$" (edit to match the urls you would like to remove the Set-Cookie)

Removing Cache Headers:

Follow the same process as above, but change the header rule to the following:

Name: Remove Cache-Control: private (or your preferred name)
Type / Action: Cache / Delete
Destination: http.Cache-Control
Source:  "private"

Overriding Default and Forcing Cache:

Create a new Cache Setting in Settings > Cache Settings and fill in the fields:

Name: Cache Static Content (or your preferred name)
TTL: 31556952 (your desired TTL in seconds)
Stale TTL:  3600 (how long your stale object will live in seconds)
Action:  Cache

Add a condition to your Cache setting by clicking on the gear icon, and fill out the following fields:

Name: Static Content Only
Apply If: req.url ~ ".(png|jpg|css|js)$"

!!Adding a condition to your cache setting is very important or you will force these cache settings globally and potentially cache private content. This may also cause unexpected behavior with gzipping!!