# LruCacheKt

Added in 1.3.0

*** ** * ** ***


```
public final class LruCacheKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/collection/LruCache<@https://developer.android.com/reference/androidx/annotation/NonNull K, @https://developer.android.com/reference/androidx/annotation/NonNull V>` | `<K extends https://developer.android.com/reference/java/lang/Object.html, V extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/collection/LruCacheKt#lruCache(kotlin.Int,kotlin.Function2,kotlin.Function1,kotlin.Function4)( int maxSize, @https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull key, @https://developer.android.com/reference/androidx/annotation/NonNull value, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html> sizeOf, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull key, V> create, @https://developer.android.com/reference/androidx/annotation/NonNull Function4<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html, @https://developer.android.com/reference/androidx/annotation/NonNull key, @https://developer.android.com/reference/androidx/annotation/NonNull oldValue, newValue, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onEntryRemoved )` Creates an `https://developer.android.com/reference/androidx/collection/LruCache` with the given parameters. |

## Public methods

### lruCache

Artifact: [androidx.collection:collection](https://developer.android.com/jetpack/androidx/releases/collection) [View Source](https://cs.android.com/search?q=file:androidx/collection/LruCache.kt+function:lruCache) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/collection#1.3.0)

```
public static final @NonNull LruCache<@NonNull K, @NonNull V> <K extends Object, V extends Object> lruCache(
    int maxSize,
    @NonNull Function2<@NonNull key, @NonNull value, @NonNull Integer> sizeOf,
    @NonNull Function1<@NonNull key, V> create,
    @NonNull Function4<@NonNull Boolean, @NonNull key, @NonNull oldValue, newValue, Unit> onEntryRemoved
)
```

Creates an `https://developer.android.com/reference/androidx/collection/LruCache` with the given parameters.

| Parameters |
|---|---|
| `int maxSize` | for caches that do not specify `https://developer.android.com/reference/androidx/collection/package-summary#lruCache(kotlin.Int,kotlin.Function2,kotlin.Function1,kotlin.Function4)`, this is the maximum number of entries in the cache. For all other caches, this is the maximum sum of the sizes of the entries in this cache. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function2<@https://developer.android.com/reference/androidx/annotation/NonNull key, @https://developer.android.com/reference/androidx/annotation/NonNull value, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Integer.html> sizeOf` | function that returns the size of the entry for key and value in user-defined units. The default implementation returns 1. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull key, V> create` | a create called after a cache miss to compute a value for the corresponding key. Returns the computed value or null if no value can be computed. The default implementation returns null. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function4<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Boolean.html, @https://developer.android.com/reference/androidx/annotation/NonNull key, @https://developer.android.com/reference/androidx/annotation/NonNull oldValue, newValue, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onEntryRemoved` | a function called for entries that have been evicted or removed. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/collection/LruCache#sizeOf(kotlin.Any,kotlin.Any)` |   |
| `https://developer.android.com/reference/androidx/collection/LruCache#create(kotlin.Any)` |   |
| `https://developer.android.com/reference/androidx/collection/LruCache#entryRemoved(kotlin.Boolean,kotlin.Any,kotlin.Any,kotlin.Any)` |   |