Getting started
Basics
Domains & Origins
Performance

Configuration
Basics
Conditions
Dictionaries
Domains & Origins
Request settings
Cache settings
Headers
Responses
Performance
Purging
Custom VCL
Image optimization
Video

Security
Access Control Lists
Monitoring and testing
Securing communications
Security measures
TLS
Web Application Firewall

Integrations
Logging endpoints
Non-Fastly services

Diagnostics
Streaming logs
Debugging techniques
Common errors

Account info
Account management
Billing
User access and control

Reference

    Controlling caching

      Last updated October 15, 2019

    When we store your content in cache, we calculate a Time to Live (TTL). The TTL is the maximum amount of time we will use the content to answer requests without consulting your origin server. After the TTL expires, we may keep the content in storage, but we won't use it to answer requests unless we're able to revalidate it with your origin.

    There's no guarantee that the content will stay cached for the length of time specified in the TTL. Depending on the size of the object and how popular it is relative to other objects, we may delete it before its TTL expires.

    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.

    Determining the TTL of an object

    You can determine the TTL of an individual object as follows:

    You can change this limit on the Configuration page.

    Setting different TTLs for Fastly cache and web browsers

    Purging objects from the Fastly cache is easy. Clearing the caches of users' web browsers is much harder. For that reason, it can make sense to set different TTLs for content in the Fastly cache versus users' web browsers. You can set different TTLs for the Fastly cache and web browsers through Surrogate-Control headers defined by the W3C. For example, if you wanted Fastly to cache something for a year but you also wanted to set a maximum age of a single day for users viewing that object in a web browser, then you could return the following HTTP headers:

    1
    2
    
    Surrogate-Control: max-age=31557600
    Cache-Control: max-age=86400
    

    The Surrogate-Control header in this example tells Fastly to cache the object for a maximum of 31557600 seconds (one year). 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 Edit 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. In the Apply if field, create a condition that matches the URLs you want.

      In this example, we created req.url!~ "^/(cacheable|images|assets)" to 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 cache setting that is set to Pass ensures the URLs are explicitly not cached.

    9. Click the Save and apply to button.
    10. Click the Activate button to deploy your configuration changes.
    Back to Top