Controlling caching

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.

  1. Log in to the Fastly application.
  2. Click on the configure button (the wrench icon at the top of the application window).

    the configure tab

  3. Select the appropriate service from the Service menu.

  4. Click the blue Configure button to the right of the displayed service name.

  5. Click Settings from the section list on the left.

    the Settings pane

  6. In the Cache Settings area, click the green New button to create a new cache setting. The New Cache Settings window appears.

    the New Cache Settings window

  7. 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.

  8. Click the gear icon to the right of the newly created cache setting and then select Conditions from the menu.

    the Conditions selection from a cache setting

    The Choose Condition window appears.

    the Choose Condition window

  9. Click the New button on the Choose Condition window. The New Condition window appears.

    the New Condition window

  10. 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.

    the New Condition window

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:

Additional resources:

Back to Top