Cloudfront CacheControl

Overview


This article describes the behavior of CloudFront cache settings.




Precedence

Behaviors are evaluated in order of priority (the lower the number, the higher the priority). If the URI matches the path pattern, subsequent behaviors are not evaluated.

Path pattern

As shown in the image, suppose three path patterns are set.
You can disable the cache by following these steps.

  • blog/*
  • index.html
  • Default (*)

If the URI is http://example.com/about/index.html, the cache operation is not applied to the first behavior because the path pattern does not match.
The second behavior matches the path pattern, so the cache operation is applied.
The third behavior is not evaluated.


Caching Disabled

For some reason, you may not want CloudFront to cache files.

  1. Select the behavior and choose Edit.
  2. For Cache and origin request settings, select Cache policy and origin request policy (recommended).
  3. For Cache Policy, Select CachingDisabled.

Confirmation of cache hits

To check for cache hits, run the following command in Powershell.

1$web = Invoke-WebRequest <URI>
2$web.Headers

If X-Cache is Miss from cloudfront, the file is retrieved from the origin.
If X-Cache is Hit from cloudfront, the file is retrieved from cache.


Translations: