Skip to main content

Policies

Cache Key#

Captain CDN uses cache keys for objects that are in the CDN edge locations, they are unique identifiers for every object and their function is to determine whether a viewer request results in a cache hit. A cache hit occurs when a viewer request generates the same cache key as the prior request, and the object for that cache key is in the cache server and valid. When the cache hit occurs, the object is served from the edge cache server to the viewer, reducing load on your origin server and reducing the latency for the viewer.

Understanding cache policies#

You can use cache policies to improve your cache hit ratio by controlling the values (URL, query strings, HTTP headers, and cookies) that are included in the cache key. Captain CDN provides some system cache policies for most common use cases. You can use these templates when you create a distribution at the cache behavior settings or you can create your own cache policies specific to your needs.

A cache policy contains the following settings:

  1. Info

    • Name - a name to identify the cache policy, you use this name to attach the cache policy to a cache behavior.
    • Comment - a comment that describes the cache policy. This field is optional but it can help you identify the purpose of the cache policy.
  2. Time to live (TTL) settings

    Time to live (TTL) settings work together with the Cache-Control and Expires HTTP headers (if they are in the origin response) to determine how long objects in the CDN cache remain valid.

    • Minimum TTL - the minimum amount of time in seconds, that you want objects to stay in CDN cache before CDN checks with the origin to see if the object has been updated.
    • Maximum TTL - the maximum amount of time in seconds that objects stay in the CDN cache before CDN checks with the origin to see if the object has been updated.
    • Default TTL - the default amount of time, in seconds, that you want objects to stay in the CDN cache before CDN checks with the origin to see if the object has been updated.
    1. Cache key contents.

Cache key settings specify the values in the viewer requests that CDN includes in the cache key. The values can include, URL query strings, HTTP headers, and cookies. The values that you include in the cache key are automatically included in requests that CDN sends to the origin.

  • Query strings - the URL query strings in the viewer requests that CDN includes in the cache key and in origin requests.

    • All - all query strings in the viewer request are included in the cache key and are also included in origin requests.
    • None - the query strings in the viewer requests are not included in the cache key and are not included in origin requests.
    • Whitelist - you can specify the query strings from the viewer requests which are going to be included in the cache key and in origin requests.
  • Headers - HTTP headers in viewer requests that CDN includes in the cache key and in origin requests.

    • None - the HTTP headers in viewer requests are not included in the cache key and origin requests.
    • Whitelist - you specify which of the HTTP headers by their name, not their value.
  • Cookies - the cookies in viewer requests that CDN includes in the cache key and in origin requests

    • All - all cookies in the viewer request are included in the cache key and are also included in origin requests.
    • None - cookies in the viewer request are not included in the cache key and are also included in origin requests.
    • Whitelist - you specify which of the cookies in viewer requests are included in the cache key and origin requests.

Creating cache policies#

  1. In Captain CDN go to Policies.
  2. Choose Create Cache Policy.
  3. Choose the desired settings.
  4. When finished click on Create.

To attach a cache key policy to existing distribution:

  1. Go to Distribution page and choose Behavior tab.
  2. Choose the cache behavior to update and select Edit, or create new cache behavior.
  3. Make sure that Use a cache policy and origin request policy at the Cache and Origin request settings is selected.
  4. For Cache Policy choose the cache policy to attach to this cache behavior.
  5. At the bottom of the page choose Update.

Origin Request#

When a viewer request to CDN results in a cache miss, the requested object is not cached in the edge cache server, CDN sends a request to the origin server to retrieve the object. This is called an origin request. The origin request always includes the following information from the viewer request.

  • The URL path (the path only, without URL query strings or the domain name)
  • The request body (if there is one)
  • The HTTP headers that CDN automatically includes in each origin request.

If you want to add more information to the viewer request such as URL query strings, HTTP Headers, and cookies, that are not included by default in the origin request, you can use an origin request policy to control what information is included in an origin request.

Origin request policies are separate from cache policies, which are used to control the cache key. This separation enables you to receive additional information at the origin and also maintain a good cache hit ratio. You do this by controlling which information is included in the origin request by using origin request policy and which is included in the cache key by using the cache policy.

The two policies are also related in terms of all the URL query strings, HTTP header, Cookies that you include in the cache key using cache policy, are automatically included in the origin requests. Origin request policy is used to specify the information that you want to include in origin requests but that are not included in the cache key. You attach a origin policy to a cache behavior to one or more cache behaviors in a CDN distribution.

Understanding origin request policies#

For most common use cases, Captain CDN provides ready to use origin requests policies. You can use these templates or you can create your own based on your needs.

An origin request policy contains the following settings:

  1. Policy Information
    • Name - a name to identify the origin request policy.You use this name to attach the origin request policy to a cache behavior.
    • Comment - a comment to describe the origin request policy.
  2. Origin Request Content

Origin request settings specify the values in the viewer requests that are included in requests that CDN sends to the origin. The values specified here are included in the origin request, but not included in the cache key.

  • Query strings - the URL query strings in the viewer requests that CDN includes in the origin requests.
    • All - all query strings in the viewer requests are included in the origin requests.
    • None - the query strings in the viewer requests are not included in the origin requests.
    • Whitelist - you can specify the query strings from the viewer requests which are going to be included in the origin requests.
  • Headers - The HTTP headers in viewer requests that CDN includes in origin requests. For headers, you can choose one of the following settings:
    • None - the HTTP headers in viewer requests are not included in origin requests.
    • All viewer headers - all HTTP headers in viewer requests are included in origin requests.
    • Whitelist - you specify which HTTP headers are included in origin requests.
    • All viewer headers and CDN custom headers - all HTTP headers in viewer requests are included in origin requests. Additionally, you specify which of the CDN headers you want to add to origin requests.
  • Cookies - The cookies in viewer requests that CDN includes in origin requests. For cookies, you can choose one of the following settings:
    • None - the cookies in viewer requests are not included in origin requests.
    • All - all cookies in viewer requests are included in origin requests.
    • Whitelist - you specify which of the cookies in viewer requests are included in origin requests.

Creating origin request policies#

  1. In Captain CDN go to Policies.
  2. Choose Create Origin Request Policy.
  3. Choose the desired settings.
  4. When finished click on Create.

To attach an origin request policy to existing distribution

  1. Go to Distribution page and choose Behavior tab
  2. Choose the cache behavior to update and select Edit, or create new cache behavior.
  3. Make sure that Use a cache policy and origin request policy at the Cache and Origin request settings is selected.
  4. For Origin Request choose the cache policy to attach to this cache behavior.
  5. At the bottom of the page choose Update.