Skip to content
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

Use AndroidX's LruCache. #2327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ buildscript {
mockWebServer: "com.squareup.okhttp3:mockwebserver:${versions.okhttp}",
pollexor: 'com.squareup:pollexor:3.0.0',
androidxAnnotations: 'androidx.annotation:annotation:1.3.0',
androidxCore: 'androidx.core:core:1.6.0',
androidxCore: 'androidx.core:core-ktx:1.6.0',
androidxCursorAdapter: 'androidx.cursoradapter:cursoradapter:1.0.0',
androidxExifInterface: 'androidx.exifinterface:exifinterface:1.3.3',
androidxFragment: 'androidx.fragment:fragment:1.4.0',
Expand Down
12 changes: 4 additions & 8 deletions picasso/src/main/java/com/squareup/picasso3/PlatformLruCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@
package com.squareup.picasso3

import android.graphics.Bitmap
import android.util.LruCache
import androidx.core.util.lruCache

/** A memory cache which uses a least-recently used eviction policy. */
internal class PlatformLruCache(maxByteCount: Int) {
/** Create a cache with a given maximum size in bytes. */
val cache =
object : LruCache<String, BitmapAndSize>(if (maxByteCount != 0) maxByteCount else 1) {
override fun sizeOf(
key: String,
value: BitmapAndSize
): Int = value.byteCount
}
val cache = lruCache<String, BitmapAndSize>(
maxByteCount.coerceAtLeast(1), { _, value -> value.byteCount }
)
afollestad marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down