Skip to content

Commit

Permalink
Include Parameter values in the cache key by default. (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrtwhite authored Mar 20, 2020
1 parent b1e6153 commit f0c97bb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion coil-base/src/main/java/coil/request/Parameters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Parameters private constructor(
* @param cacheKey The parameter's cache key. If not null, this value will be added to a request's cache key.
*/
@JvmOverloads
fun set(key: String, value: Any?, cacheKey: String? = null) = apply {
fun set(key: String, value: Any?, cacheKey: String? = value?.toString()) = apply {
this.map[key] = Entry(value, cacheKey)
}

Expand Down
2 changes: 1 addition & 1 deletion coil-base/src/main/java/coil/request/RequestBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ sealed class RequestBuilder<T : RequestBuilder<T>> {
* @see Parameters.Builder.set
*/
@JvmOverloads
fun setParameter(key: String, value: Any?, cacheKey: String? = null): T = self {
fun setParameter(key: String, value: Any?, cacheKey: String? = value?.toString()): T = self {
this.parameters = (this.parameters ?: Parameters.Builder()).apply { set(key, value, cacheKey) }
}

Expand Down
6 changes: 3 additions & 3 deletions coil-base/src/test/java/coil/RealImageLoaderBasicTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,9 @@ class RealImageLoaderBasicTest {

private fun createFakeParameters(): Parameters {
return Parameters.Builder()
.set("key1", "no_cache")
.set("key2", "cached2", "cached2")
.set("key3", "cached3", "cached3")
.set("key1", "no_cache", cacheKey = null)
.set("key2", "cached2")
.set("key3", "cached3")
.build()
}

Expand Down
2 changes: 1 addition & 1 deletion coil-sample/src/main/java/coil/sample/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MainViewModel(application: Application, handle: SavedStateHandle) : Androi
for (index in 0 until 50) {
val videoFrameMicros = Random.nextLong(62000000L)
val parameters = Parameters.Builder()
.set(VIDEO_FRAME_MICROS_KEY, videoFrameMicros, videoFrameMicros.toString())
.set(VIDEO_FRAME_MICROS_KEY, videoFrameMicros)
.build()

images += Image(
Expand Down

0 comments on commit f0c97bb

Please sign in to comment.