LruCacheKt

Added in 1.3.0

public final class LruCacheKt


Summary

Public methods

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 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,
    @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 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.

@NonNull Function2<@NonNull key, @NonNull value, @NonNull Integer> sizeOf

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

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

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

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