How long Fastly caches content
The maximum amount of time we cache content depends on a number of factors including the TTL (Time To Live) and Grace Period, how often an object gets accessed, and how busy other customers are. Setting TTL and Grace Period to a week, possibly even two weeks should be absolutely fine. For more information about controlling how long Fastly caches your resources, start with our Cache Control Tutorial.
In general, we will honor any cache-control headers you send to us from your origin; however, if you do not send any cache-control headers, you will most likely reach the Default TTL limit for your service. You can change this limit in the Configuration Control Panel under the Settings pane.
Changing caching times for different users
You can change the caching times for different users through Surrogate-Control headers defined by the W3C. If, for example, you wanted Fastly to cache something for a month (clearing with API purges, if necessary) but you also wanted to set a maximum age of a single day for users viewing that object in a browser, then you could return the HTTP header:
Surrogate-Control: max-age=2629744 Cache-Control: max-age=86400
The Surrogate Control header in this example tells Fastly to cache the object for a maximum of 2629744 seconds (one month). The Cache Control header in this example tells the browser to cache the object for a maximum of 86400 seconds (1 day).
For more information about controlling caching, see our Cache Control Tutorial.
Conditionally preventing pages from caching
To conditionally prevent pages from caching, follow the steps below.
- Log in to the Fastly application.
Click on the configure button (the wrench icon at the top of the application window).
Select the appropriate service from the Service menu.
Click the blue Configure button to the right of the displayed service name.
Click Settings from the section list on the left.
In the Cache Settings area, click the green New button to create a new cache setting. The New Cache Settings window appears.
Create a new cache setting and click then click the Create button. For more information about the actions, see our descriptions of caching actions. The new cache setting you created appears in the Cache Settings area of the Settings pane on the Configuration tab.
Click the gear icon to the right of the newly created cache setting and then select Conditions from the menu.
The Choose Condition window appears.
Click the New button on the Choose Condition window. The New Condition window appears.
Create a condition that matches against the URLs you want and then click the Create button. In this example, we set the condition to look for URLs containing '/cacheable', '/images', or '/assets'. If it finds them, the URLs should be cached. If it doesn't find them, the URLs are explicitly not cached by the Apply If statement shown below.
Caching action descriptions
You can use actions to tell Fastly what to do with cached objects and what to do with additional cache configurations as a result. The following actions are available:
- N/A - Applies the cache settings within the policy and continues through to other cache configurations.
- Deliver - Delivers the object to the client. Usually returned from
- Pass - Passes the request and subsequent response to and from the origin server. It won't be cached. Pass can be returned from
- Restart - Restarts processing of the request. You can restart the processing of the whole transaction. Changes to the
reqobject are retained.