这是indexloc提供的服务,不要输入任何密码
Skip to content

Add ability to cache by response content, check if response was actually changed even if it expired, return same headers on 304 and 200 #13274

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

OlegYch
Copy link
Contributor

@OlegYch OlegYch commented May 19, 2025

The primary reason for this is to increase performance by decreasing the amount of result content returned from server side and utilizing 304 response headers to drive the client to make less requests.

This also brings Cached implementation closer to http spec by:

  1. actually using response content as described by https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
  2. preserving headers as described by https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304

For performance reasons this still uses two cache entries per resource, to avoid retrieving potentially large result content from potentially remote cache.

For compatibility reasons new ability is gated via play.cache.hashResponse config entry. It should probably become default in the future as the old ETag value based on expiration date (essentially random value) doesn't seem to be useful or specified anywhere in http. The config value and relevant code should be removed then.

cc @julienrf as the original author
cc @alexdupre as the most recent functionality contributor

@mkurz
Copy link
Member

mkurz commented May 19, 2025

Is there any issue or related PR?

@OlegYch
Copy link
Contributor Author

OlegYch commented May 19, 2025

@mkurz not that i've seen

@alexdupre
Copy link
Contributor

I support the change from a conceptual point of view, it's a noticeable improvement. I looked at the commit briefly, I'd suggest to create the hash of the response content in a streamed way (e.g. via a DigestOutputStream), instead of materializing the entire byte array, though.

…lly changed even if it expired, return same headers on 304 and 200

This brings Cached implementation closer to http spec by:
1. actually using response content as described by https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
2. preserving headers as described by https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/304

For performance reasons this still uses two cache entries per resource, to avoid retrieving potentially large result content from potentially remote cache.

For compatibility reasons new ability is gated via `play.cache.hashResponse` config entry.
It should probably become default in the future as the old ETag value based on expiration date (essentially random value) doesn't seem to be useful or specified anywhere in http.
The config value and relevant code should be removed then.
@OlegYch
Copy link
Contributor Author

OlegYch commented May 20, 2025

@alexdupre makes sense, updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants