Skip to content

org.jetbrains.kotlin.analysis.api.platform.caches

Types

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.

NullableConcurrentCache

@JvmInline
value class NullableConcurrentCache<K : Any, V>(val map: ConcurrentMap<K, Any> = ConcurrentHashMap())

A wrapper around a ConcurrentMap which stores null values returned by the computation in the form of explicit objects.

NullValue

object NullValue

An object used as a representative for null in collections which prohibit null values.

Functions

getOrPut

fun <K : Any, V : Any> Cache<K, V>.getOrPut(key: K, 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.

getOrPutWithNullableValue

inline fun <K : Any, R> Cache<K, Any>.getOrPutWithNullableValue(key: K, crossinline compute: (K) -> Any?): R

Implements Cache.getOrPut with NullValue conversion.

inline fun <K : Any, R> ConcurrentMap<K, Any>.getOrPutWithNullableValue(key: K, crossinline compute: (K) -> Any?): R

Implements ConcurrentMap.getOrPut with NullValue conversion.

nullValueToNull

inline fun <V> Any.nullValueToNull(): V

Converts NullValue to null, and all other instances of this to V.

withStatsCounter

fun <K, V> Caffeine<K, V>.withStatsCounter(statsCounter: StatsCounter?): Caffeine<K, V>

Applies the StatsCounter to the Caffeine cache builder if it's non-null, or otherwise doesn't register it.