Skip to content

Commit a59dc0c

Browse files
authored
feat(codepipeline-actions): more convenient methods to CacheControl (#28491)
This PR adds following convenient methods to `CacheControl`; same as #25477. | method | directive | RFC | |-|-|-| | `CacheControl.noStore()` | `no-store` | [RFC9111](https://www.rfc-editor.org/rfc/rfc9111.html), Section 5.2.2.4 | | `CacheControl.mustUnderstand()` | `must-understand` | RFC9111, Section 5.2.2.3 | | `CacheControl.immutable()` | `immutable` | [RFC8246](https://www.rfc-editor.org/rfc/rfc8246.html) | | `CacheControl.staleWhileRevalidate(duration)` | `stale-while-revalidate=<duration>` | [RFC5861](https://www.rfc-editor.org/rfc/rfc5861.html) | | `CacheControl.staleIfError(duration)` | `stale-if-error=<duration>` | RFC5861 | For more information about these Cache-Control directives, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 0b345c5 commit a59dc0c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/aws-cdk-lib/aws-codepipeline-actions/lib/s3/deploy-action.ts

+10
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,26 @@ export class CacheControl {
2525
public static noCache() { return new CacheControl('no-cache'); }
2626
/** The 'no-transform' cache control directive. */
2727
public static noTransform() { return new CacheControl('no-transform'); }
28+
/** The 'no-store' cache control directive. */
29+
public static noStore() { return new CacheControl('no-store'); }
30+
/** The 'must-understand' cache control directive. */
31+
public static mustUnderstand() { return new CacheControl('must-understand'); }
2832
/** The 'public' cache control directive. */
2933
public static setPublic() { return new CacheControl('public'); }
3034
/** The 'private' cache control directive. */
3135
public static setPrivate() { return new CacheControl('private'); }
36+
/** The 'immutable' cache control directive. */
37+
public static immutable() { return new CacheControl('immutable'); }
3238
/** The 'proxy-revalidate' cache control directive. */
3339
public static proxyRevalidate() { return new CacheControl('proxy-revalidate'); }
3440
/** The 'max-age' cache control directive. */
3541
public static maxAge(t: Duration) { return new CacheControl(`max-age=${t.toSeconds()}`); }
3642
/** The 's-max-age' cache control directive. */
3743
public static sMaxAge(t: Duration) { return new CacheControl(`s-maxage=${t.toSeconds()}`); }
44+
/** The 'stale-while-revalidate' cache control directive. */
45+
public static staleWhileRevalidate(t: Duration) { return new CacheControl(`stale-while-revalidate=${t.toSeconds()}`); }
46+
/** The 'stale-if-error' cache control directive. */
47+
public static staleIfError(t: Duration) { return new CacheControl(`stale-if-error=${t.toSeconds()}`); }
3848
/**
3949
* Allows you to create an arbitrary cache control directive,
4050
* in case our support is missing a method for a particular directive.

packages/aws-cdk-lib/aws-codepipeline-actions/test/s3/s3-deploy-action.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ describe('S3 Deploy Action', () => {
125125
});
126126
});
127127

128+
test('cache-control directive has correct values', () => {
129+
expect(cpactions.CacheControl.mustRevalidate().value).toEqual('must-revalidate');
130+
expect(cpactions.CacheControl.noCache().value).toEqual('no-cache');
131+
expect(cpactions.CacheControl.noTransform().value).toEqual('no-transform');
132+
expect(cpactions.CacheControl.noStore().value).toEqual('no-store');
133+
expect(cpactions.CacheControl.mustUnderstand().value).toEqual('must-understand');
134+
expect(cpactions.CacheControl.setPublic().value).toEqual('public');
135+
expect(cpactions.CacheControl.setPrivate().value).toEqual('private');
136+
expect(cpactions.CacheControl.immutable().value).toEqual('immutable');
137+
expect(cpactions.CacheControl.proxyRevalidate().value).toEqual('proxy-revalidate');
138+
expect(cpactions.CacheControl.maxAge(Duration.minutes(1)).value).toEqual('max-age=60');
139+
expect(cpactions.CacheControl.sMaxAge(Duration.minutes(1)).value).toEqual('s-maxage=60');
140+
expect(cpactions.CacheControl.staleWhileRevalidate(Duration.minutes(1)).value).toEqual('stale-while-revalidate=60');
141+
expect(cpactions.CacheControl.staleIfError(Duration.minutes(1)).value).toEqual('stale-if-error=60');
142+
expect(cpactions.CacheControl.fromString('custom').value).toEqual('custom');
143+
});
144+
128145
test('allow customizing objectKey (deployment path on S3)', () => {
129146
const stack = new Stack();
130147
minimalPipeline(stack, {

0 commit comments

Comments
 (0)