AWS Fundamentals Logo
AWS Fundamentals
L2 Construct

CachePolicy

A Cache Policy configuration.

Import

import { CachePolicy } from 'aws-cdk-lib/aws-cloudfront';

Or use the module namespace:

import * as cloudfront from 'aws-cdk-lib/aws-cloudfront';
// cloudfront.CachePolicy

Properties

Configuration passed to the constructor as CachePolicyProps.

cachePolicyNameOptional
string

A unique name to identify the cache policy. The name must only include '-', '_', or alphanumeric characters.

Default: - generated from the `id`

commentOptional
string

A comment to describe the cache policy. The comment cannot be longer than 128 characters.

Default: - no comment

cookieBehaviorOptional
CacheCookieBehavior

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: CacheCookieBehavior.none()

defaultTtlOptional
Duration

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: - The greater of 1 day and ``minTtl``

enableAcceptEncodingBrotliOptional
boolean

Whether to normalize and include the `Accept-Encoding` header in the cache key when the `Accept-Encoding` header is 'br'.

Default: false

enableAcceptEncodingGzipOptional
boolean

Whether to normalize and include the `Accept-Encoding` header in the cache key when the `Accept-Encoding` header is 'gzip'.

Default: false

headerBehaviorOptional
CacheHeaderBehavior

Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin.

Default: CacheHeaderBehavior.none()

maxTtlOptional
Duration

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: - The greater of 1 year and ``defaultTtl``

minTtlOptional
Duration

The minimum amount of time for objects to stay in the CloudFront cache.

Default: Duration.seconds(0)

queryStringBehaviorOptional
CacheQueryStringBehavior

Determines whether any query strings are included in the cache key and automatically included in requests that CloudFront sends to the origin.

Default: CacheQueryStringBehavior.none()

Get the Amazon CloudFront Cheat Sheet

Everything you need to know about Amazon CloudFront on one page. HD quality, print-friendly.

Download Free Infographic