# CachePolicyProps

Properties for creating a Cache Policy.

Extends: CachePolicyProps
Used as props by: CachePolicy

- Source: [`aws-cloudfront/lib/cache-policy.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-cloudfront/lib/cache-policy.ts#L33)

## 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

- `cachePolicyName`: string — A unique name to identify the cache policy.

  **Default:** generated from the `id`

  The name must only include '-', '_', or alphanumeric characters.

- `comment`: string — A comment to describe the cache policy.

  **Default:** no comment

  The comment cannot be longer than 128 characters.

- `cookieBehavior`: [CacheCookieBehavior](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.CacheCookieBehavior.html) = 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`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — 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.

- `enableAcceptEncodingBrotli`: boolean = false — Whether to normalize and include the `Accept-Encoding` header in the cache key when the `Accept-Encoding` header is 'br'.

- `enableAcceptEncodingGzip`: boolean = false — Whether to normalize and include the `Accept-Encoding` header in the cache key when the `Accept-Encoding` header is 'gzip'.

- `headerBehavior`: [CacheHeaderBehavior](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.CacheHeaderBehavior.html) = 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`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — 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.

- `minTtl`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.seconds(0) — The minimum amount of time for objects to stay in the CloudFront cache.

- `queryStringBehavior`: [CacheQueryStringBehavior](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudfront.CacheQueryStringBehavior.html) = CacheQueryStringBehavior.none() — Determines whether any query strings are included in the cache key and automatically included in requests that CloudFront sends to the origin.
