CachePolicyProps Struct
Properties for creating a Cache Policy.
Example
ts
// Creating a custom cache policy for a Distribution -- all parameters optional
declare const bucketOrigin: origins.S3Origin;
const myCachePolicy = new cloudfront.CachePolicy(this, 'myCachePolicy', {
cachePolicyName: 'MyPolicy',
comment: 'A default policy',
defaultTtl: Duration.days(2),
minTtl: Duration.minutes(1),
maxTtl: Duration.days(10),
cookieBehavior: cloudfront.CacheCookieBehavior.all(),
headerBehavior: cloudfront.CacheHeaderBehavior.allowList('X-CustomHeader'),
queryStringBehavior: cloudfront.CacheQueryStringBehavior.denyList('username'),
enableAcceptEncodingGzip: true,
enableAcceptEncodingBrotli: true,
});
new cloudfront.Distribution(this, 'myDistCustomPolicy', {
defaultBehavior: {
origin: bucketOrigin,
cachePolicy: myCachePolicy,
},
});
Properties
cachePolicyNamestringcache_policy_namestrcachePolicyNameStringCachePolicyNamestringCachePolicyName*string= generated from the `id`#A unique name to identify the cache policy.
The name must only include '-', '_', or alphanumeric characters.
A comment to describe the cache policy.
The comment cannot be longer than 128 characters.
cookieBehaviorCacheCookieBehaviorcookie_behaviorCacheCookieBehaviorcookieBehaviorCacheCookieBehaviorCookieBehaviorCacheCookieBehaviorCookieBehaviorCacheCookieBehavior= CacheCookieBehavior.none()#Determines whether any cookies in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin.
defaultTtlDurationdefault_ttlDurationdefaultTtlDurationDefaultTtlDurationDefaultTtlDuration= The greater of 1 day and ``minTt…#The default amount of time for objects to stay in the CloudFront cache.
Only used when the origin does not send Cache-Control or Expires headers with the object.
default
Default: The greater of 1 day and minTtl
enableAcceptEncodingBrotlibooleanenable_accept_encoding_brotliboolenableAcceptEncodingBrotliBooleanEnableAcceptEncodingBrotliboolEnableAcceptEncodingBrotli*bool= false#Whether to normalize and include the `Accept-Encoding` header in the cache key when the `Accept-Encoding` header is 'br'.
enableAcceptEncodingGzipbooleanenable_accept_encoding_gzipboolenableAcceptEncodingGzipBooleanEnableAcceptEncodingGzipboolEnableAcceptEncodingGzip*bool= false#Whether to normalize and include the `Accept-Encoding` header in the cache key when the `Accept-Encoding` header is 'gzip'.
headerBehaviorCacheHeaderBehaviorheader_behaviorCacheHeaderBehaviorheaderBehaviorCacheHeaderBehaviorHeaderBehaviorCacheHeaderBehaviorHeaderBehaviorCacheHeaderBehavior= CacheHeaderBehavior.none()#Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin.
maxTtlDurationmax_ttlDurationmaxTtlDurationMaxTtlDurationMaxTtlDuration= The greater of 1 year and ``defa…#The maximum amount of time for objects to stay in the CloudFront cache.
CloudFront uses this value only when the origin sends Cache-Control or Expires headers with the object.
default
Default: The greater of 1 year and defaultTtl
The minimum amount of time for objects to stay in the CloudFront cache.
queryStringBehaviorCacheQueryStringBehaviorquery_string_behaviorCacheQueryStringBehaviorqueryStringBehaviorCacheQueryStringBehaviorQueryStringBehaviorCacheQueryStringBehaviorQueryStringBehaviorCacheQueryStringBehavior= CacheQueryStringBehavior.none()#Determines whether any query strings are included in the cache key and automatically included in requests that CloudFront sends to the origin.