Segmented Caching

      Last updated April 19, 2021

    Fastly’s Segmented Caching feature allows you to cache resources of any size. Segmented Caching works by breaking resources into smaller segments in Fastly’s cache then recombining or splitting these resources to respond to arbitrary size byte Range: requests from clients. Once enabled, Segmented Caching improves performance for Range: requests and allows Fastly to efficiently cache resources of any size.

    How Segmented Caching works

    When an end user makes a Range: request for a resource with Segmented Caching enabled and a cache miss occurs (that is, at least part of the range is not cached), Fastly will make the appropriate Range: requests back to origin. Segmented Caching will then ensure only the specific portions of the resource that have been requested by the end user (along with rounding based on object size) will be cached rather than the entire resource. Partial cache hits will result in having the cached portion served from cache and the missing pieces fetched from origin. (Requests for an entire resource would be treated as a byte Range: request from 0 to end of resource.)

    Once Fastly has all of the objects necessary to respond to an end user’s request, the Segmented Caching feature will assemble the response by concatenating or pulling portions of objects. The requests back to origin, also called “inner requests,” will have a true value for segmented_caching.is_inner_req and requests from end users, also called “outer requests,” will have a true value for segmented_caching.is_outer_req. If a request is made for an object without segmented caching enabled, both variables will have a FALSE value.

    Limitations and considerations

    This feature has the following limitations and considerations you should take into account:

    Enabling Segmented Caching

    Use the following steps to enable Segmented Caching.

    1. Determine which resources should use Segmented Caching.

    2. From the All services page, select the appropriate service. You can use the search box to search by ID, name, or domain.
    3. Click the Edit configuration button and then select the option to clone the active version. The Domains page appears.
    4. Click the VCL Snippets link. The VCL Snippets page appears.
    5. Click the Create your first VCL snippet button. The Create a VCL snippet page appears.
    6. In the Name field, type an appropriate name (e.g., Enable segmented caching).
    7. From the Type (placement of the snippets) controls, select within subroutine.
    8. From the Select subroutine menu, select recv (vcl_recv).
    9. In the VCL field, add a VCL snippet that sets the req.enable_segmented_caching VCL variable to true in vcl_recv. For example, to ensure proper caching of the large resources you've identified that contain MPEG-2-compressed video data, you could add this VCL snippet in vcl_recv:

      # my custom enabled Segmented Caching code
      if (req.url.ext == "ts") {
         set req.enable_segmented_caching = true;

      This snippet tells Fastly to look for requests for files with the ts extension and then enable Segmented Caching for those files.

    10. Click Create to create the snippet.
    11. Click the Activate button to deploy your configuration changes.
    Back to Top