Class CachePolicy
java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.cloudfront.CachePolicy
- All Implemented Interfaces:
IEnvironmentAware,IResource,ICachePolicy,ICachePolicyRef,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
@Generated(value="jsii-pacmak/1.118.0 (build 02eec31)",
date="2025-11-04T09:27:36.056Z")
@Stability(Stable)
public class CachePolicy
extends Resource
implements ICachePolicy
A Cache Policy configuration.
Example:
// Create the simple Origin
Bucket myBucket = new Bucket(this, "myBucket");
IOrigin s3Origin = S3BucketOrigin.withOriginAccessControl(myBucket, S3BucketOriginWithOACProps.builder()
.originAccessLevels(List.of(AccessLevel.READ, AccessLevel.LIST))
.build());
// Create the Distribution construct
Distribution myMultiTenantDistribution = Distribution.Builder.create(this, "distribution")
.defaultBehavior(BehaviorOptions.builder()
.origin(s3Origin)
.build())
.defaultRootObject("index.html")
.build();
// Access the underlying L1 CfnDistribution to configure SaaS Manager properties which are not yet available in the L2 Distribution construct
CfnDistribution cfnDistribution = (CfnDistribution)myMultiTenantDistribution.getNode().getDefaultChild();
DefaultCacheBehaviorProperty defaultCacheBehavior = DefaultCacheBehaviorProperty.builder()
.targetOriginId(myBucket.getBucketArn())
.viewerProtocolPolicy("allow-all")
.compress(false)
.allowedMethods(List.of("GET", "HEAD"))
.cachePolicyId(CachePolicy.CACHING_OPTIMIZED.getCachePolicyId())
.build();
// Create the updated distributionConfig
DistributionConfigProperty distributionConfig = DistributionConfigProperty.builder()
.defaultCacheBehavior(defaultCacheBehavior)
.enabled(true)
// the properties below are optional
.connectionMode("tenant-only")
.origins(List.of(OriginProperty.builder()
.id(myBucket.getBucketArn())
.domainName(myBucket.getBucketDomainName())
.s3OriginConfig(S3OriginConfigProperty.builder().build())
.originPath("/{{tenantName}}")
.build()))
.tenantConfig(TenantConfigProperty.builder()
.parameterDefinitions(List.of(ParameterDefinitionProperty.builder()
.definition(DefinitionProperty.builder()
.stringSchema(StringSchemaProperty.builder()
.required(false)
// the properties below are optional
.comment("tenantName")
.defaultValue("root")
.build())
.build())
.name("tenantName")
.build()))
.build())
.build();
// Override the distribution configuration to enable multi-tenancy.
cfnDistribution.getDistributionConfig() = distributionConfig;
// Create a distribution tenant using an existing ACM certificate
CfnDistributionTenant cfnDistributionTenant = CfnDistributionTenant.Builder.create(this, "distribution-tenant")
.distributionId(myMultiTenantDistribution.getDistributionId())
.domains(List.of("my-tenant.my.domain.com"))
.name("my-tenant")
.enabled(true)
.parameters(List.of(ParameterProperty.builder()
.name("tenantName")
.value("app")
.build()))
.customizations(CustomizationsProperty.builder()
.certificate(CertificateProperty.builder()
.arn("REPLACE_WITH_ARN")
.build())
.build())
.build();
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationModeNested classes/interfaces inherited from interface software.amazon.awscdk.services.cloudfront.ICachePolicy
ICachePolicy.Jsii$Default, ICachePolicy.Jsii$ProxyNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ICachePolicyThis policy is designed for use with an origin that is an AWS Amplify web app.static final ICachePolicyDisables caching.static final ICachePolicyOptimize cache efficiency by minimizing the values that CloudFront includes in the cache key.static final ICachePolicyOptimize cache efficiency by minimizing the values that CloudFront includes in the cache key.static final ICachePolicyDesigned for use with an origin that is an AWS Elemental MediaPackage endpoint.static final StringUniquely identifies this class.static final ICachePolicyDesigned for use with an origin that returns Cache-Control HTTP response headers and does not serve different content based on values present in the query string.static final ICachePolicyDesigned for use with an origin that returns Cache-Control HTTP response headers and serves different content based on values present in the query string. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCachePolicy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedCachePolicy(software.amazon.jsii.JsiiObjectRef objRef) CachePolicy(software.constructs.Construct scope, String id) CachePolicy(software.constructs.Construct scope, String id, CachePolicyProps props) -
Method Summary
Modifier and TypeMethodDescriptionstatic ICachePolicyfromCachePolicyId(software.constructs.Construct scope, String id, String cachePolicyId) Imports a Cache Policy from its id.The ID of the cache policy.A reference to a CachePolicy resource.Methods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResourceMethods inherited from class software.constructs.Construct
getNode, isConstruct, toStringMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.constructs.IConstruct
getNodeMethods inherited from interface software.amazon.awscdk.IEnvironmentAware
getEnvMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
AMPLIFY
This policy is designed for use with an origin that is an AWS Amplify web app. -
CACHING_DISABLED
Disables caching.This policy is useful for dynamic content and for requests that are not cacheable.
-
CACHING_OPTIMIZED
Optimize cache efficiency by minimizing the values that CloudFront includes in the cache key.Query strings and cookies are not included in the cache key, and only the normalized 'Accept-Encoding' header is included.
-
CACHING_OPTIMIZED_FOR_UNCOMPRESSED_OBJECTS
Optimize cache efficiency by minimizing the values that CloudFront includes in the cache key.Query strings and cookies are not included in the cache key, and only the normalized 'Accept-Encoding' header is included. Disables cache compression.
-
ELEMENTAL_MEDIA_PACKAGE
Designed for use with an origin that is an AWS Elemental MediaPackage endpoint. -
PROPERTY_INJECTION_ID
Uniquely identifies this class. -
USE_ORIGIN_CACHE_CONTROL_HEADERS
Designed for use with an origin that returns Cache-Control HTTP response headers and does not serve different content based on values present in the query string. -
USE_ORIGIN_CACHE_CONTROL_HEADERS_QUERY_STRINGS
Designed for use with an origin that returns Cache-Control HTTP response headers and serves different content based on values present in the query string.
-
-
Constructor Details
-
CachePolicy
protected CachePolicy(software.amazon.jsii.JsiiObjectRef objRef) -
CachePolicy
protected CachePolicy(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) -
CachePolicy
@Stability(Stable) public CachePolicy(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable CachePolicyProps props) - Parameters:
scope- This parameter is required.id- This parameter is required.props-
-
CachePolicy
@Stability(Stable) public CachePolicy(@NotNull software.constructs.Construct scope, @NotNull String id) - Parameters:
scope- This parameter is required.id- This parameter is required.
-
-
Method Details
-
fromCachePolicyId
@Stability(Stable) @NotNull public static ICachePolicy fromCachePolicyId(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String cachePolicyId) Imports a Cache Policy from its id.- Parameters:
scope- This parameter is required.id- This parameter is required.cachePolicyId- This parameter is required.
-
getCachePolicyId
The ID of the cache policy.- Specified by:
getCachePolicyIdin interfaceICachePolicy
-
getCachePolicyRef
A reference to a CachePolicy resource.- Specified by:
getCachePolicyRefin interfaceICachePolicyRef
-