LruCacheKt

public final class LruCacheKt


Summary

Public methods

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

Creates an LruCache with the given parameters.

Public methods

lruCache

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

Creates an LruCache with the given parameters.

Parameters
int maxSize

for caches that do not specify sizeOf, 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.

Function2<key, value, Integer> sizeOf

function that returns the size of the entry for key and value in user-defined units. The default implementation returns 1.

Function1<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.

Function4<Boolean, key, oldValue, newValue, Unit> onEntryRemoved

a function called for entries that have been evicted or removed.