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#A unique name to identify the cache policy.
Default: generated from the id
The name must only include '-', '_', or alphanumeric characters.
A comment to describe the cache policy.
Default: no comment
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.
The default amount of time for objects to stay in the CloudFront cache.
Default: The greater of 1 day and minTtl
Only used when the origin does not send Cache-Control or Expires headers with the object.
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.
The maximum amount of time for objects to stay in the CloudFront cache.
Default: The greater of 1 year and defaultTtl
CloudFront uses this value only when the origin sends Cache-Control or Expires headers with the object.
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.