We've been making changes to how we organize and display our docs. Our work isn't done but we'd love your feedback.
Getting started
Domains & Origins

Domains & Origins
Request settings
Cache settings
Custom VCL
Image optimization

Access Control Lists
Monitoring and testing
Securing communications
Web Application Firewall

Logging endpoints
Non-Fastly services

Streaming logs
Debugging techniques
Common errors

Account info
Account management
User access and control


    Controlling caching

      Last updated August 09, 2018

    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.

    You can determine what your default TTL for your service will be as follows:

    You can change this limit on the Configuration page.

    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 Surrogate-Control, Fastly supports the max-age, stale-if-error, and stale-while-revalidate parameters.

    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 web interface and click the Configure link.
    2. From the service menu, select the appropriate service.
    3. Click the Configuration button and then select Clone active. The Domains page appears.
    4. Click the Settings link. The Settings page appears.
    5. Click the Create cache setting button to create a new cache setting. The Create a cache setting page appears.

      the Cache Settings window

    6. Create a new cache setting and then click the Create button. The new cache setting you created appears on the Settings page.
    7. Click the Attach a condition link to the right of the newly created cache setting. The Create a new cache condition window appears.

      the New Condition window

    8. Create a condition that matches the URLs you want and then click the Save and apply to button. In this example, we set the condition to look for URLs containing /cacheable, /images, or /assets. If the condition finds them, the URLs should be cached. If the condition doesn't find them, the URLs are explicitly not cached by the apply if statement shown above.
    9. Click the Activate button to deploy your configuration changes.

    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:

    Back to Top