Skip to content

Commit 05d4e76

Browse files
Use AndroidX's LruCache.
1 parent e03dd35 commit 05d4e76

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ buildscript {
2020
mockWebServer: "com.squareup.okhttp3:mockwebserver:${versions.okhttp}",
2121
pollexor: 'com.squareup:pollexor:3.0.0',
2222
androidxAnnotations: 'androidx.annotation:annotation:1.3.0',
23-
androidxCore: 'androidx.core:core:1.6.0',
23+
androidxCore: 'androidx.core:core-ktx:1.6.0',
2424
androidxCursorAdapter: 'androidx.cursoradapter:cursoradapter:1.0.0',
2525
androidxExifInterface: 'androidx.exifinterface:exifinterface:1.3.3',
2626
androidxFragment: 'androidx.fragment:fragment:1.4.0',

picasso/src/main/java/com/squareup/picasso3/PlatformLruCache.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@
1616
package com.squareup.picasso3
1717

1818
import android.graphics.Bitmap
19-
import android.util.LruCache
19+
import androidx.core.util.lruCache
2020

2121
/** A memory cache which uses a least-recently used eviction policy. */
2222
internal class PlatformLruCache(maxByteCount: Int) {
2323
/** Create a cache with a given maximum size in bytes. */
24-
val cache =
25-
object : LruCache<String, BitmapAndSize>(if (maxByteCount != 0) maxByteCount else 1) {
26-
override fun sizeOf(
27-
key: String,
28-
value: BitmapAndSize
29-
): Int = value.byteCount
30-
}
24+
val cache = lruCache<String, BitmapAndSize>(
25+
maxByteCount.coerceAtLeast(1), { _, value -> value.byteCount }
26+
)
3127

3228
operator fun get(key: String): Bitmap? = cache[key]?.bitmap
3329

0 commit comments

Comments
 (0)