-
Notifications
You must be signed in to change notification settings - Fork 685
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
Fix memory cache miss when Transformation reduces input bitmap's size. #357
Conversation
|
||
/** Remove all values from this cache. */ | ||
fun clearMemory() | ||
|
||
/** @see ComponentCallbacks2.onTrimMemory */ | ||
fun trimMemory(level: Int) | ||
|
||
/** Cache key for [MemoryCache] and [WeakMemoryCache]. */ | ||
class Key { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No data class, unfortunately, since we need to be able to control when size
is null using the constructors.
@@ -62,14 +85,14 @@ class Parameters private constructor( | |||
|
|||
class Builder { | |||
|
|||
private val map: SortedMap<String, Entry> | |||
private val map: MutableMap<String, Entry> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this sorted before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhh gotcha. Thanks for clarifying!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Glad to see this is fixed!
#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 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 aCircleCropTransformation
inImageListAdapter
.This requires a broader refactor to convert the memory cache's key from
String
to 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 (likeParameters
having to always order its entries the same way irrespective of insertion order).Added regression tests to guard against this going forward.