Skip to content

Add RFC-8246 "immutable" attribute to CacheControl #29955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

making
Copy link
Member

@making making commented Feb 10, 2023

This commit adds the "immutable" Cache-Control directives in CacheControl.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This commit adds the "immutable" Cache-Control directives in `CacheControl`.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 10, 2023
@bclozel bclozel self-assigned this Feb 10, 2023
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Feb 14, 2023
@rstoyanchev rstoyanchev changed the title Add RFC-8246 support to CacheControl Add RFC-8246 "immutable" attribute to CacheControl Feb 14, 2023
@bclozel bclozel added this to the 6.0.5 milestone Feb 14, 2023
@bclozel bclozel removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 14, 2023
@bclozel
Copy link
Member

bclozel commented Feb 14, 2023

Thanks for the PR @making !
The CacheControl API tries to guide developers towards HTTP best practices for "Cache-Control" header values, with static factory methods and instance methods.

In this case, the popular use case uses both a max-age and the immutable directive, like so: "Cache-Control: max-age=31536000, immutable". The goal here is to instruct the browser that the response should not be revalidated as long as it's not stale, giving a long "max-age" value.

We could have enforced this by requiring a "max-age" value if the freshness directive is used. This is not technically enforced by the RFC. Without such a value, browsers are likely to fall back to heuristics caching, effectively caching the resource for (current date - last modified date) / 10.

At the time of this comment, numerous browsers aren't supporting this directive: Edge, Chrome, Android browsers, Opera. Because of that, most implementations should use a max-age value in all cases for compatibility.

We won't enforce the need for max-age, but we should probably guide developers there with the Javadoc.

@bclozel bclozel closed this in 616e777 Feb 14, 2023
bclozel added a commit that referenced this pull request Feb 14, 2023
Polish

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
See gh-29955
@making making deleted the cache-control-immutable branch February 15, 2023 08:27
izeye added a commit to izeye/spring-framework that referenced this pull request Feb 17, 2023
Polish

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@izeye izeye mentioned this pull request Feb 17, 2023
sbrannen pushed a commit that referenced this pull request Feb 19, 2023
Polishing

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
See gh-23846
See gh-29955
Closes gh-29992
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants