Fix memory cache miss when Transformation reduces input bitmap's size.#357
Merged
Conversation
colinrtwhite
commented
Apr 9, 2020
| fun trimMemory(level: Int) | ||
|
|
||
| /** Cache key for [MemoryCache] and [WeakMemoryCache]. */ | ||
| class Key { |
Member
Author
There was a problem hiding this comment.
No data class, unfortunately, since we need to be able to control when size is null using the constructors.
Jawnnypoo
reviewed
Apr 9, 2020
| class Builder { | ||
|
|
||
| private val map: SortedMap<String, Entry> | ||
| private val map: MutableMap<String, Entry> |
Member
Author
There was a problem hiding this comment.
@Jawnnypoo The iteration order had to be consistent irrespective of insertion order so the cache key would match up. If we didn't sort by keys, the parameters would produce two difference cache keys. E.g.
val parameters = Parameters.Builder()
.set("key1", "first_value")
.set("key2", "second_value")
.build()
// would produce the string cache key "key1=first_value#key2=second_value"
val parameters = Parameters.Builder()
.set("key2", "second_value")
.set("key1", "first_value")
.build()
// would produce the string cache key "key2=second_value#key1=first_value"One of the gotchas of using a string cache key. Now order doesn't matter since Parameters are compared using Map.equals!
Member
There was a problem hiding this comment.
Ahhhh gotcha. Thanks for clarifying!
Jawnnypoo
approved these changes
Apr 9, 2020
Member
Jawnnypoo
left a comment
There was a problem hiding this comment.
Awesome! Glad to see this is fixed!
colinrtwhite
added a commit
that referenced
this pull request
Oct 5, 2022
#357) * Fix memory cache miss when Transformation reduces input bitmap's size. * Update API. * Re-add toString(). * Add regression test. * Update API. * cache -> cached. * Remove signature. * Re-arrange params. * isCachedDrawableValid -> isCachedValueValid. * Update equals. * Fix style.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a bug where a request could miss the memory cache if it uses a transformation that decreases the output bitmap's height (e.g.
CircleCropTransformation). It's reproducible on master if you add aCircleCropTransformationinImageListAdapter.This requires a broader refactor to convert the memory cache's key from
Stringto a custom object so we can hold onto the request's resolved size. Overall, I've been planning to move away from using a String cache key for a while as it has gotchas (likeParametershaving to always order its entries the same way irrespective of insertion order).Added regression tests to guard against this going forward.