Cache behavior

In CloudFront, we have the ability to control the behavior of the distribution we create in several different ways. We can decide what kinds of HTTP request methods we allow to be forwarded to our distribution. We can select three types of requests to be forwarded:

  • GET and HEAD: Used for static content caching, such as media and static websites.
  • GET, HEAD, and OPTIONS: Used for static content on servers that have several communication options enabled.
  • GET, HEAD, OPTIONS, PUT, PATCH, POST, and DELETE: Used for caching and terminating dynamic HTTP sessions at the CloudFront Edge Location. This allows us to speed up the write requests to our backend API or WebSockets environment.

We can also control the time-to-live (TTL) of our cache by controlling the CloudFront distribution options. This allows us to automatically expire content and give the environment the ability to regularly refresh the content being served from the cache. We should set the TTL values appropriately, according to the way our content is life cycled. CloudFront distributions support the following options for setting TTL:

  • Min TTL: Required when forwarding all headers. The value determines the minimum time our objects will be served from CloudFront caches. After the Min TTL expires, CloudFront will connect to the origin and check if the object has been updated. Min TTL will override any shorter TTLs defined for objects in the origin server.
  • Default TTL: An optional value that can define the cache TTL if no specific TTL is defined in the origin. Must be longer than Min TTL if defined.
  • Max TTL: Also optional and will define the longest possible period that objects can stay in the cache. This value, contrary to Default TTL, is only used with requests where the origin is specifying the cache data in the headers and is designed to override any cache control entries from the origin that are set too long. 

Other cache control features allow control of the following:

  • Traffic compression and encryption with the Compress and FieldLevelEncryptionId options
  • Lambda function execution with the LambdaFunctionAssociations option
  • Handling of strings, cookies, and patterns with the ForwardedValues, PathPattern, and TargetOriginId options
  • Private and streaming content with the TrustedSigners and SmoothStreaming options
  • How we treat HTTP and HTTPS requests with the ViewerProtocolPolicy option
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.3.175