interface CachePolicyProps
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.CloudFront.CachePolicyProps |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#CachePolicyProps |
Java | software.amazon.awscdk.services.cloudfront.CachePolicyProps |
Python | aws_cdk.aws_cloudfront.CachePolicyProps |
TypeScript (source) | aws-cdk-lib » aws_cloudfront » CachePolicyProps |
Properties for creating a Cache Policy.
Example
// 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
Name | Type | Description |
---|---|---|
cache | string | A unique name to identify the cache policy. |
comment? | string | A comment to describe the cache policy. |
cookie | Cache | Determines whether any cookies in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin. |
default | Duration | The default amount of time for objects to stay in the CloudFront cache. |
enable | boolean | Whether to normalize and include the Accept-Encoding header in the cache key when the Accept-Encoding header is 'br'. |
enable | boolean | Whether to normalize and include the Accept-Encoding header in the cache key when the Accept-Encoding header is 'gzip'. |
header | Cache | Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin. |
max | Duration | The maximum amount of time for objects to stay in the CloudFront cache. |
min | Duration | The minimum amount of time for objects to stay in the CloudFront cache. |
query | Cache | Determines whether any query strings are included in the cache key and automatically included in requests that CloudFront sends to the origin. |
cachePolicyName?
Type:
string
(optional, default: generated from the id
)
A unique name to identify the cache policy.
The name must only include '-', '_', or alphanumeric characters.
comment?
Type:
string
(optional, default: no comment)
A comment to describe the cache policy.
The comment cannot be longer than 128 characters.
cookieBehavior?
Type:
Cache
(optional, default: 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.
defaultTtl?
Type:
Duration
(optional, default: The greater of 1 day and minTtl
)
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.
enableAcceptEncodingBrotli?
Type:
boolean
(optional, default: false)
Whether to normalize and include the Accept-Encoding
header in the cache key when the Accept-Encoding
header is 'br'.
enableAcceptEncodingGzip?
Type:
boolean
(optional, default: false)
Whether to normalize and include the Accept-Encoding
header in the cache key when the Accept-Encoding
header is 'gzip'.
headerBehavior?
Type:
Cache
(optional, default: CacheHeaderBehavior.none())
Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin.
maxTtl?
Type:
Duration
(optional, default: The greater of 1 year and defaultTtl
)
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.
minTtl?
Type:
Duration
(optional, default: Duration.seconds(0))
The minimum amount of time for objects to stay in the CloudFront cache.
queryStringBehavior?
Type:
Cache
(optional, default: CacheQueryStringBehavior.none())
Determines whether any query strings are included in the cache key and automatically included in requests that CloudFront sends to the origin.