# CacheControl

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

Obtainable from: CacheControl.fromString, CacheControl.immutable, CacheControl.maxAge, CacheControl.mustRevalidate, CacheControl.mustUnderstand, CacheControl.noCache, CacheControl.noStore, CacheControl.noTransform, CacheControl.proxyRevalidate, CacheControl.sMaxAge, CacheControl.setPrivate, CacheControl.setPublic, CacheControl.staleIfError, CacheControl.staleWhileRevalidate

- Source: [`aws-s3-deployment/lib/bucket-deployment.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.ts#L835)
- Type last changed: v2.81.0 · 25 May 2023

## Example

TypeScript:

```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:

```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:

```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();
```

C# / .NET:

```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
});
```

Golang:

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

- `value`: any — The raw cache control setting.

## Methods

- `fromString(s: string): CacheControl // chainable` (static) — Constructs a custom cache control key from the literal value.

- `immutable(): CacheControl // chainable` (static) — Sets 'immutable'.

- `maxAge(t: Duration): CacheControl // chainable` (static) — Sets 'max-age=<duration-in-seconds>'.

- `mustRevalidate(): CacheControl // chainable` (static) — Sets 'must-revalidate'.

- `mustUnderstand(): CacheControl // chainable` (static) — Sets 'must-understand'.

- `noCache(): CacheControl // chainable` (static) — Sets 'no-cache'.

- `noStore(): CacheControl // chainable` (static) — Sets 'no-store'.

- `noTransform(): CacheControl // chainable` (static) — Sets 'no-transform'.

- `proxyRevalidate(): CacheControl // chainable` (static) — Sets 'proxy-revalidate'.

- `setPrivate(): CacheControl // chainable` (static) — Sets 'private'.

- `setPublic(): CacheControl // chainable` (static) — Sets 'public'.

- `sMaxAge(t: Duration): CacheControl // chainable` (static) — Sets 's-maxage=<duration-in-seconds>'.

- `staleIfError(t: Duration): CacheControl // chainable` (static) — Sets 'stale-if-error=<duration-in-seconds>'.

- `staleWhileRevalidate(t: Duration): CacheControl // chainable` (static) — Sets 'stale-while-revalidate=<duration-in-seconds>'.
