inline fun <K : Any, V : Any> lruCache(maxSize: Int, crossinline sizeOf: (key: K, value: V) -> Int = { _, _ -> 1 }, crossinline create: (key: K) -> V? = { null as V? }, crossinline onEntryRemoved: (evicted: Boolean, key: K, oldValue: V, newValue: V?) -> Unit = { _, _, _, _ -> }): LruCache<K, V>
Creates an LruCache with the given parameters.
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.
sizeOf
- function that returns the size of the entry for key and value in
user-defined units. The default implementation returns 1.
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.
onEntryRemoved
- a function called for entries that have been evicted or removed.
See Also