library / org.akop.kotx.ext.collections / android.util.LruCache

Extensions for android.util.LruCache

getOrPut

fun <K, V> LruCache<K, V>.getOrPut(key: K, defaultValue: () -> V): V

Gets value with specific key from the cache. If the value is not present, calls defaultValue to obtain a non-null value which is placed into the cache, then returned.

getOrPutNotNull

fun <K, V> LruCache<K, V>.getOrPutNotNull(key: K, defaultValue: () -> V?): V?

Gets value with specific key from the cache. If the value is not present, calls defaultValue to obtain a value which is placed into the cache if not null, then returned.

keys

fun <V> LruCache<Int, V>.keys(): IntArray
fun <V> LruCache<Long, V>.keys(): LongArray
fun <K, V> LruCache<K, V>.keys(): Array<K>

Returns an array containing the keys in the cache.