Skip to content
v2.278.0

CacheControl Class ​

Used for HTTP cache-control header, which influences downstream caches.

Example ​

ts
declare const destinationBucket: s3.Bucket;
new s3deploy.BucketDeployment(this, 'BucketDeployment', {
  sources: [s3deploy.Source.asset('./website', { exclude: ['index.html'] })],
  destinationBucket,
  cacheControl: [
    s3deploy.CacheControl.maxAge(Duration.days(365)),
    s3deploy.CacheControl.immutable(),
  ],
  prune: false,
});

new s3deploy.BucketDeployment(this, 'HTMLBucketDeployment', {
  sources: [s3deploy.Source.asset('./website', { exclude: ['*', '!index.html'] })],
  destinationBucket,
  cacheControl: [
    s3deploy.CacheControl.maxAge(Duration.seconds(0)),
  ],
  prune: false,
});
python
# destination_bucket: s3.Bucket

s3deploy.BucketDeployment(self, "BucketDeployment",
    sources=[s3deploy.Source.asset("./website", exclude=["index.html"])],
    destination_bucket=destination_bucket,
    cache_control=[
        s3deploy.CacheControl.max_age(Duration.days(365)),
        s3deploy.CacheControl.immutable()
    ],
    prune=False
)

s3deploy.BucketDeployment(self, "HTMLBucketDeployment",
    sources=[s3deploy.Source.asset("./website", exclude=["*", "!index.html"])],
    destination_bucket=destination_bucket,
    cache_control=[
        s3deploy.CacheControl.max_age(Duration.seconds(0))
    ],
    prune=False
)
java
Bucket destinationBucket;

BucketDeployment.Builder.create(this, "BucketDeployment")
        .sources(List.of(Source.asset("./website", AssetOptions.builder().exclude(List.of("index.html")).build())))
        .destinationBucket(destinationBucket)
        .cacheControl(List.of(CacheControl.maxAge(Duration.days(365)), CacheControl.immutable()))
        .prune(false)
        .build();

BucketDeployment.Builder.create(this, "HTMLBucketDeployment")
        .sources(List.of(Source.asset("./website", AssetOptions.builder().exclude(List.of("*", "!index.html")).build())))
        .destinationBucket(destinationBucket)
        .cacheControl(List.of(CacheControl.maxAge(Duration.seconds(0))))
        .prune(false)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
Bucket destinationBucket;

new BucketDeployment(this, "BucketDeployment", new BucketDeploymentProps {
    Sources = new [] { Source.Asset("./website", new AssetOptions { Exclude = new [] { "index.html" } }) },
    DestinationBucket = destinationBucket,
    CacheControl = new [] { CacheControl.MaxAge(Duration.Days(365)), CacheControl.Immutable() },
    Prune = false
});

new BucketDeployment(this, "HTMLBucketDeployment", new BucketDeploymentProps {
    Sources = new [] { Source.Asset("./website", new AssetOptions { Exclude = new [] { "*", "!index.html" } }) },
    DestinationBucket = destinationBucket,
    CacheControl = new [] { CacheControl.MaxAge(Duration.Seconds(0)) },
    Prune = false
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var destinationBucket Bucket

s3deploy.NewBucketDeployment(this, jsii.String("BucketDeployment"), &BucketDeploymentProps{
	Sources: []ISource{
		s3deploy.Source_Asset(jsii.String("./website"), &AssetOptions{
			Exclude: []*string{
				jsii.String("index.html"),
			},
		}),
	},
	DestinationBucket: DestinationBucket,
	CacheControl: []CacheControl{
		s3deploy.CacheControl_MaxAge(awscdk.Duration_Days(jsii.Number(365))),
		s3deploy.CacheControl_Immutable(),
	},
	Prune: jsii.Boolean(false),
})

s3deploy.NewBucketDeployment(this, jsii.String("HTMLBucketDeployment"), &BucketDeploymentProps{
	Sources: []ISource{
		s3deploy.Source_*Asset(jsii.String("./website"), &AssetOptions{
			Exclude: []*string{
				jsii.String("*"),
				jsii.String("!index.html"),
			},
		}),
	},
	DestinationBucket: DestinationBucket,
	CacheControl: []CacheControl{
		s3deploy.CacheControl_*MaxAge(awscdk.Duration_Seconds(jsii.Number(0))),
	},
	Prune: jsii.Boolean(false),
})

Properties ​

valueanyvalueAnyvalueObjectValueobjectValueinterface{} #
The raw cache control setting.

Methods ​

fromString(s: string): CacheControl // chainable@staticmethod def from_string(s: str) -> CacheControlpublic static CacheControl fromString(String s)public static CacheControl FromString(string s)func FromString(S *string) CacheControl static #
Constructs a custom cache control key from the literal value.
immutable(): CacheControl // chainable@staticmethod def immutable() -> CacheControlpublic static CacheControl immutable()public static CacheControl Immutable()func Immutable() CacheControl static #
Sets 'immutable'.
maxAge(t: Duration): CacheControl // chainable@staticmethod def max_age(t: Duration) -> CacheControlpublic static CacheControl maxAge(Duration t)public static CacheControl MaxAge(Duration t)func MaxAge(T Duration) CacheControl static #
Sets 'max-age=<duration-in-seconds>'.
mustRevalidate(): CacheControl // chainable@staticmethod def must_revalidate() -> CacheControlpublic static CacheControl mustRevalidate()public static CacheControl MustRevalidate()func MustRevalidate() CacheControl static #
Sets 'must-revalidate'.
mustUnderstand(): CacheControl // chainable@staticmethod def must_understand() -> CacheControlpublic static CacheControl mustUnderstand()public static CacheControl MustUnderstand()func MustUnderstand() CacheControl static #
Sets 'must-understand'.
noCache(): CacheControl // chainable@staticmethod def no_cache() -> CacheControlpublic static CacheControl noCache()public static CacheControl NoCache()func NoCache() CacheControl static #
Sets 'no-cache'.
noStore(): CacheControl // chainable@staticmethod def no_store() -> CacheControlpublic static CacheControl noStore()public static CacheControl NoStore()func NoStore() CacheControl static #
Sets 'no-store'.
noTransform(): CacheControl // chainable@staticmethod def no_transform() -> CacheControlpublic static CacheControl noTransform()public static CacheControl NoTransform()func NoTransform() CacheControl static #
Sets 'no-transform'.
proxyRevalidate(): CacheControl // chainable@staticmethod def proxy_revalidate() -> CacheControlpublic static CacheControl proxyRevalidate()public static CacheControl ProxyRevalidate()func ProxyRevalidate() CacheControl static #
Sets 'proxy-revalidate'.
setPrivate(): CacheControl // chainable@staticmethod def set_private() -> CacheControlpublic static CacheControl setPrivate()public static CacheControl SetPrivate()func SetPrivate() CacheControl static #
Sets 'private'.
setPublic(): CacheControl // chainable@staticmethod def set_public() -> CacheControlpublic static CacheControl setPublic()public static CacheControl SetPublic()func SetPublic() CacheControl static #
Sets 'public'.
sMaxAge(t: Duration): CacheControl // chainable@staticmethod def s_max_age(t: Duration) -> CacheControlpublic static CacheControl sMaxAge(Duration t)public static CacheControl SMaxAge(Duration t)func SMaxAge(T Duration) CacheControl static #
Sets 's-maxage=<duration-in-seconds>'.
staleIfError(t: Duration): CacheControl // chainable@staticmethod def stale_if_error(t: Duration) -> CacheControlpublic static CacheControl staleIfError(Duration t)public static CacheControl StaleIfError(Duration t)func StaleIfError(T Duration) CacheControl static #
Sets 'stale-if-error=<duration-in-seconds>'.
staleWhileRevalidate(t: Duration): CacheControl // chainable@staticmethod def stale_while_revalidate(t: Duration) -> CacheControlpublic static CacheControl staleWhileRevalidate(Duration t)public static CacheControl StaleWhileRevalidate(Duration t)func StaleWhileRevalidate(T Duration) CacheControl static #
Sets 'stale-while-revalidate=<duration-in-seconds>'.