Skip to content

Commit 0f45d0d

Browse files
Use AndroidX's LruCache.
1 parent 6298eed commit 0f45d0d

2 files changed

Lines changed: 6 additions & 10 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: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,16 @@
1616
package com.squareup.picasso3
1717

1818
import android.graphics.Bitmap
19-
import android.util.LruCache
2019
import androidx.core.graphics.BitmapCompat
20+
import androidx.core.util.lruCache
2121

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

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

0 commit comments

Comments
 (0)