Skip to content
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

KTOR-6001 Cache returns null when vary header has more fields in the cached response #3655

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

rsinukov
Copy link
Contributor

@rsinukov rsinukov commented Jun 13, 2023

@rsinukov rsinukov requested a review from marychatte June 13, 2023 14:37
Copy link
Member

@marychatte marychatte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, accidentally missed this pr :) I have some comments

@@ -42,7 +42,9 @@ internal class UnlimitedStorage : CacheStorage {

override suspend fun find(url: Url, varyKeys: Map<String, String>): CachedResponseData? {
val data = store.computeIfAbsent(url) { ConcurrentSet() }
return data.find { it.varyKeys == varyKeys }
return data.find {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one more find function on line 23, should we also change it like here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the legacy storage, but I changed it as well. Thanks!

@@ -42,7 +42,9 @@ internal class UnlimitedStorage : CacheStorage {

override suspend fun find(url: Url, varyKeys: Map<String, String>): CachedResponseData? {
val data = store.computeIfAbsent(url) { ConcurrentSet() }
return data.find { it.varyKeys == varyKeys }
return data.find {
varyKeys.all { (key, value) -> it.varyKeys[key] == value }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also check the equal size of maps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's ok if cached version has more vary properties, than the 304 response

@rsinukov rsinukov requested a review from marychatte June 26, 2023 10:49
Copy link
Member

@marychatte marychatte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rsinukov rsinukov merged commit cbf747e into main Jun 26, 2023
@rsinukov rsinukov deleted the rsinukov/vary-304-fix branch June 26, 2023 11:33
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.

2 participants