Skip to content

Commit 5335778

Browse files
committed
Polish
See gh-29955
1 parent 616e777 commit 5335778

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

spring-web/src/main/java/org/springframework/http/CacheControl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -326,6 +326,8 @@ public CacheControl staleIfError(Duration staleIfError) {
326326
* Add an "immutable" directive.
327327
* <p>This directive indicates that the origin server will not update the
328328
* representation of that resource during the freshness lifetime of the response.
329+
* Adding a {@link #maxAge(Duration) max-age} directive is strongly advised
330+
* to enforce the actual freshness lifetime.
329331
* @return {@code this}, to facilitate method chaining
330332
* @see <a href="https://tools.ietf.org/html/rfc8246">rfc8246</a>
331333
*/

spring-web/src/test/java/org/springframework/http/CacheControlTests.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,84 +25,85 @@
2525

2626

2727
/**
28+
* Tests for {@link CacheControl}.
2829
* @author Brian Clozel
2930
*/
30-
public class CacheControlTests {
31+
class CacheControlTests {
3132

3233
@Test
33-
public void emptyCacheControl() throws Exception {
34+
void emptyCacheControl() {
3435
CacheControl cc = CacheControl.empty();
3536
assertThat(cc.getHeaderValue()).isNull();
3637
}
3738

3839
@Test
39-
public void maxAge() throws Exception {
40+
void maxAge() {
4041
CacheControl cc = CacheControl.maxAge(1, TimeUnit.HOURS);
4142
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600");
4243
}
4344

4445
@Test
45-
public void maxAge_duration() throws Exception {
46+
void maxAge_duration() {
4647
CacheControl cc = CacheControl.maxAge(Duration.ofHours(1));
4748
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600");
4849
}
4950

5051
@Test
51-
public void maxAgeAndDirectives() throws Exception {
52+
void maxAgeAndDirectives() {
5253
CacheControl cc = CacheControl.maxAge(3600, TimeUnit.SECONDS).cachePublic().noTransform();
5354
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600, no-transform, public");
5455
}
5556

5657
@Test
57-
public void maxAgeAndSMaxAge() throws Exception {
58+
void maxAgeAndSMaxAge() {
5859
CacheControl cc = CacheControl.maxAge(1, TimeUnit.HOURS).sMaxAge(30, TimeUnit.MINUTES);
5960
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600, s-maxage=1800");
6061
}
6162

6263
@Test
63-
public void maxAgeAndSMaxAge_duration() throws Exception {
64+
void maxAgeAndSMaxAge_duration() {
6465
CacheControl cc = CacheControl.maxAge(Duration.ofHours(1)).sMaxAge(Duration.ofMinutes(30));
6566
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600, s-maxage=1800");
6667
}
6768

6869
@Test
69-
public void noCachePrivate() throws Exception {
70+
void noCachePrivate() {
7071
CacheControl cc = CacheControl.noCache().cachePrivate();
7172
assertThat(cc.getHeaderValue()).isEqualTo("no-cache, private");
7273
}
7374

7475
@Test
75-
public void noStore() throws Exception {
76+
void noStore() {
7677
CacheControl cc = CacheControl.noStore();
7778
assertThat(cc.getHeaderValue()).isEqualTo("no-store");
7879
}
7980

8081
@Test
81-
public void staleIfError() throws Exception {
82+
void staleIfError() {
8283
CacheControl cc = CacheControl.maxAge(1, TimeUnit.HOURS).staleIfError(2, TimeUnit.HOURS);
8384
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600, stale-if-error=7200");
8485
}
8586

8687
@Test
87-
public void staleIfError_duration() throws Exception {
88+
void staleIfError_duration() {
8889
CacheControl cc = CacheControl.maxAge(Duration.ofHours(1)).staleIfError(2, TimeUnit.HOURS);
8990
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600, stale-if-error=7200");
9091
}
9192

9293
@Test
93-
public void staleWhileRevalidate() throws Exception {
94+
void staleWhileRevalidate() {
9495
CacheControl cc = CacheControl.maxAge(1, TimeUnit.HOURS).staleWhileRevalidate(2, TimeUnit.HOURS);
9596
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600, stale-while-revalidate=7200");
9697
}
9798

9899
@Test
99-
public void staleWhileRevalidate_duration() throws Exception {
100+
void staleWhileRevalidate_duration() {
100101
CacheControl cc = CacheControl.maxAge(Duration.ofHours(1)).staleWhileRevalidate(2, TimeUnit.HOURS);
101102
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600, stale-while-revalidate=7200");
102103
}
103104

104105
@Test
105-
public void immutable() throws Exception {
106+
void immutable() {
106107
CacheControl cc = CacheControl.maxAge(Duration.ofHours(1)).immutable();
107108
assertThat(cc.getHeaderValue()).isEqualTo("max-age=3600, immutable");
108109
}

0 commit comments

Comments
 (0)