Skip to content

NullableCaffeineCache

@JvmInline
value class NullableCaffeineCache<K : Any, V : Any>(val cache: Cache<K, Any>)

A wrapper around a Caffeine Cache which stores null values returned by the computation in the form of explicit objects. On a conceptual level, this allows the cache to store failures so that future accesses to the same key don't recompute the same failure.

Constructors

NullableCaffeineCache

constructor(cache: Cache<K, Any>)
constructor(configure: (Caffeine<Any, Any>) -> Caffeine<Any, Any>)

Creates a new NullableCaffeineCache by configuring a Caffeine builder with configure.

Properties

cache

val cache: Cache<K, Any>

estimatedSize

val estimatedSize: @NonNegative Long

Returns the approximate number of entries in the cache.

Functions

get

inline fun get(key: K, crossinline compute: (K) -> V?): V?

Returns the value for the given key if it's contained in the cache, or computes the value with compute and adds it to the cache.

getOrPut

inline fun getOrPut(key: K, crossinline compute: (K) -> V?): V?

Returns the value for the given key if it's contained in the cache, or computes the value with compute outside the cache's computation lock and adds it to the cache.