diff --git a/api/cache4k/index.html b/api/cache4k/index.html index 945f7de..48c6ba2 100644 --- a/api/cache4k/index.html +++ b/api/cache4k/index.html @@ -45,7 +45,7 @@
- +
-
+

cache4k

Packages

-
-
+
+
- +
Link copied to clipboard
diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event-listener/index.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event-listener/index.html index 5c92f8a..4e91c65 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event-listener/index.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event-listener/index.html @@ -45,7 +45,7 @@
- +
-
+

CacheEventListener

-
fun interface CacheEventListener<Key : Any, Value : Any>

Definition of the contract for implementing listeners to receive CacheEvents from a Cache.

+
fun interface CacheEventListener<Key : Any, Value : Any>

Definition of the contract for implementing listeners to receive CacheEvents from a Cache.

Functions

-
-
+
+
- +
Link copied to clipboard
-
abstract fun onEvent(event: CacheEvent<Key, Value>)

Invoked on CacheEvent firing.

+
abstract fun onEvent(event: CacheEvent<Key, Value>)

Invoked on CacheEvent firing.

diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event-listener/on-event.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event-listener/on-event.html index 963eff0..f0ef696 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event-listener/on-event.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event-listener/on-event.html @@ -45,7 +45,7 @@
- +
-
+

onEvent

-
abstract fun onEvent(event: CacheEvent<Key, Value>)

Invoked on CacheEvent firing.

Cache entry event firing behaviors for mutative methods:

{}put(K, V){K: V}Created(K, V)
{K: V1}put(K, V2){K: V2}Updated(K, V1, V2)
{K: V}invalidate(K){}Removed(K, V)
{K1: V1, K2: V2}invalidateAll(){}Removed(K1, V1), Removed(K2, V2)
{K: V}any operation, K expired{}Expired(K, V)
{K1: V1}put(K2, V2), K1 evicted{K2: V2}Created(K2, V2), Evicted(K1, V1)
+
abstract fun onEvent(event: CacheEvent<Key, Value>)

Invoked on CacheEvent firing.

Cache entry event firing behaviors for mutative methods:

Initial valueOperationNew valueEvent
{}put(K, V){K: V}Created(K, V)
{K: V1}put(K, V2){K: V2}Updated(K, V1, V2)
{K: V}invalidate(K){}Removed(K, V)
{K1: V1, K2: V2}invalidateAll(){}Removed(K1, V1), Removed(K2, V2)
{K: V}any operation, K expired{}Expired(K, V)
{K1: V1}put(K2, V2), K1 evicted{K2: V2}Created(K2, V2), Evicted(K1, V1)
- +
-
+

Created

-
constructor(key: Key, value: Value)
+
constructor(key: Key, value: Value)
- +
-
+

equals

-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- +
-
+

hashCode

-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- +
-
+

Created

-
class Created<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
+
class Created<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>

Constructors

-
-
+
+
- +
Link copied to clipboard
-
constructor(key: Key, value: Value)
+
constructor(key: Key, value: Value)
@@ -88,32 +88,32 @@

Constructors

Properties

-
-
+
+
- +
Link copied to clipboard
-
open override val key: Key
+
open override val key: Key
- -
+ +
- +
Link copied to clipboard
- +
@@ -122,47 +122,47 @@

Properties

Functions

-
-
+
+
- +
Link copied to clipboard
-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- -
+ +
- +
Link copied to clipboard
-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- -
+ +
- +
Link copied to clipboard
-
open override fun toString(): String
+
open override fun toString(): String
diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-created/key.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-created/key.html index 1cd2898..f7b8074 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-created/key.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-created/key.html @@ -45,7 +45,7 @@
- +
-
+

key

-
open override val key: Key
+
open override val key: Key
- +
-
+

toString

-
open override fun toString(): String
+
open override fun toString(): String
- +
-
+

value

- +
- +
-
+

Evicted

-
constructor(key: Key, value: Value)
+
constructor(key: Key, value: Value)
- +
-
+

equals

-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- +
-
+

hashCode

-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- +
-
+

Evicted

-
class Evicted<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
+
class Evicted<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>

Constructors

-
-
+
+
- +
Link copied to clipboard
-
constructor(key: Key, value: Value)
+
constructor(key: Key, value: Value)
@@ -88,32 +88,32 @@

Constructors

Properties

-
-
+
+
- +
Link copied to clipboard
-
open override val key: Key
+
open override val key: Key
- -
+ +
- +
Link copied to clipboard
- +
@@ -122,47 +122,47 @@

Properties

Functions

-
-
+
+
- +
Link copied to clipboard
-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- -
+ +
- +
Link copied to clipboard
-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- -
+ +
- +
Link copied to clipboard
-
open override fun toString(): String
+
open override fun toString(): String
diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-evicted/key.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-evicted/key.html index 3a4222b..9edb230 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-evicted/key.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-evicted/key.html @@ -45,7 +45,7 @@
- +
-
+

key

-
open override val key: Key
+
open override val key: Key
- +
-
+

toString

-
open override fun toString(): String
+
open override fun toString(): String
- +
-
+

value

- +
- +
-
+

Expired

-
constructor(key: Key, value: Value)
+
constructor(key: Key, value: Value)
- +
-
+

equals

-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- +
-
+

hashCode

-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- +
-
+

Expired

-
class Expired<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
+
class Expired<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>

Constructors

-
-
+
+
- +
Link copied to clipboard
-
constructor(key: Key, value: Value)
+
constructor(key: Key, value: Value)
@@ -88,32 +88,32 @@

Constructors

Properties

-
-
+
+
- +
Link copied to clipboard
-
open override val key: Key
+
open override val key: Key
- -
+ +
- +
Link copied to clipboard
- +
@@ -122,47 +122,47 @@

Properties

Functions

-
-
+
+
- +
Link copied to clipboard
-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- -
+ +
- +
Link copied to clipboard
-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- -
+ +
- +
Link copied to clipboard
-
open override fun toString(): String
+
open override fun toString(): String
diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-expired/key.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-expired/key.html index 797563c..be6a830 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-expired/key.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-expired/key.html @@ -45,7 +45,7 @@
- +
-
+

key

-
open override val key: Key
+
open override val key: Key
- +
-
+

toString

-
open override fun toString(): String
+
open override fun toString(): String
- +
-
+

value

- +
- +
-
+

Removed

-
constructor(key: Key, value: Value)
+
constructor(key: Key, value: Value)
- +
-
+

equals

-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- +
-
+

hashCode

-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- +
-
+

Removed

-
class Removed<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
+
class Removed<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>

Constructors

-
-
+
+
- +
Link copied to clipboard
-
constructor(key: Key, value: Value)
+
constructor(key: Key, value: Value)
@@ -88,32 +88,32 @@

Constructors

Properties

-
-
+
+
- +
Link copied to clipboard
-
open override val key: Key
+
open override val key: Key
- -
+ +
- +
Link copied to clipboard
- +
@@ -122,47 +122,47 @@

Properties

Functions

-
-
+
+
- +
Link copied to clipboard
-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- -
+ +
- +
Link copied to clipboard
-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- -
+ +
- +
Link copied to clipboard
-
open override fun toString(): String
+
open override fun toString(): String
diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-removed/key.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-removed/key.html index 5c269fd..2112941 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-removed/key.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-removed/key.html @@ -45,7 +45,7 @@
- +
-
+

key

-
open override val key: Key
+
open override val key: Key
- +
-
+

toString

-
open override fun toString(): String
+
open override fun toString(): String
- +
-
+

value

- +
- +
-
+

Updated

-
constructor(key: Key, oldValue: Value, newValue: Value)
+
constructor(key: Key, oldValue: Value, newValue: Value)
- +
-
+

equals

-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- +
-
+

hashCode

-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- +
-
+

Updated

-
class Updated<Key : Any, Value : Any>(val key: Key, val oldValue: Value, val newValue: Value) : CacheEvent<Key, Value>
+
class Updated<Key : Any, Value : Any>(val key: Key, val oldValue: Value, val newValue: Value) : CacheEvent<Key, Value>

Constructors

-
-
+
+
- +
Link copied to clipboard
-
constructor(key: Key, oldValue: Value, newValue: Value)
+
constructor(key: Key, oldValue: Value, newValue: Value)
@@ -88,47 +88,47 @@

Constructors

Properties

-
-
+
+
- +
Link copied to clipboard
-
open override val key: Key
+
open override val key: Key
- -
+ +
- +
Link copied to clipboard
- +
- -
+ +
- +
Link copied to clipboard
- +
@@ -137,47 +137,47 @@

Properties

Functions

-
-
+
+
- +
Link copied to clipboard
-
open operator override fun equals(other: Any?): Boolean
+
open operator override fun equals(other: Any?): Boolean
- -
+ +
- +
Link copied to clipboard
-
open override fun hashCode(): Int
+
open override fun hashCode(): Int
- -
+ +
- +
Link copied to clipboard
-
open override fun toString(): String
+
open override fun toString(): String
diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-updated/key.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-updated/key.html index 01c6ee4..983fd1d 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-updated/key.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/-updated/key.html @@ -45,7 +45,7 @@
- +
-
+

key

-
open override val key: Key
+
open override val key: Key
- +
-
+

newValue

- +
- +
-
+

oldValue

- +
- +
-
+

toString

-
open override fun toString(): String
+
open override fun toString(): String
- +
-
+

CacheEvent

-
interface CacheEvent<Key : Any, Value : Any>

An event resulting from a mutative Cache operation.

Inheritors

+
interface CacheEvent<Key : Any, Value : Any>

An event resulting from a mutative Cache operation.

Inheritors

Types

-
-
+
+
- +
Link copied to clipboard
-
class Created<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
+
class Created<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
- -
+ +
- +
Link copied to clipboard
-
class Evicted<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
+
class Evicted<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
- -
+ +
- +
Link copied to clipboard
-
class Expired<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
+
class Expired<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
- -
+ +
- +
Link copied to clipboard
-
class Removed<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
+
class Removed<Key : Any, Value : Any>(val key: Key, val value: Value) : CacheEvent<Key, Value>
- -
+ +
- +
Link copied to clipboard
-
class Updated<Key : Any, Value : Any>(val key: Key, val oldValue: Value, val newValue: Value) : CacheEvent<Key, Value>
+
class Updated<Key : Any, Value : Any>(val key: Key, val oldValue: Value, val newValue: Value) : CacheEvent<Key, Value>
@@ -148,17 +148,17 @@

Types

Properties

-
-
+
+
- +
Link copied to clipboard
-
abstract val key: Key
+
abstract val key: Key
diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/key.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/key.html index 7a990d9..18d3a44 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/key.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache-event/key.html @@ -45,7 +45,7 @@
- +
-
+

key

-
abstract val key: Key
+
abstract val key: Key
- +
-
+

Companion

-
object Companion
+
object Companion

Functions

-
-
+
+
- +
Link copied to clipboard
-
operator fun <K : Any, V : Any> invoke(): Cache.Builder<K, V>

Returns a new Cache.Builder instance.

+
operator fun <K : Any, V : Any> invoke(): Cache.Builder<K, V>

Returns a new Cache.Builder instance.

diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache/-builder/-companion/invoke.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache/-builder/-companion/invoke.html index d10322d..8c06a25 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache/-builder/-companion/invoke.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache/-builder/-companion/invoke.html @@ -45,7 +45,7 @@
- +
-
+

invoke

-
operator fun <K : Any, V : Any> invoke(): Cache.Builder<K, V>

Returns a new Cache.Builder instance.

+
operator fun <K : Any, V : Any> invoke(): Cache.Builder<K, V>

Returns a new Cache.Builder instance.

- +
-
+

build

-
abstract fun build(): Cache<K, V>

Builds a new instance of Cache with the specified configurations.

+
abstract fun build(): Cache<K, V>

Builds a new instance of Cache with the specified configurations.

- +
-
+

eventListener

-
abstract fun eventListener(listener: CacheEventListener<K, V>): Cache.Builder<K, V>

Specifies a CacheEventListener to be used to handle cache events.

+
abstract fun eventListener(listener: CacheEventListener<K, V>): Cache.Builder<K, V>

Specifies a CacheEventListener to be used to handle cache events.

- +
-
+

expireAfterAccess

-
abstract fun expireAfterAccess(duration: Duration): Cache.Builder<K, V>

Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, the most recent replacement of its value, or its last access.

When duration is zero, the cache's max size will be set to 0 meaning no values will be cached.

+
abstract fun expireAfterAccess(duration: Duration): Cache.Builder<K, V>

Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, the most recent replacement of its value, or its last access.

When duration is zero, the cache's max size will be set to 0 meaning no values will be cached.

- +
-
+

expireAfterWrite

-
abstract fun expireAfterWrite(duration: Duration): Cache.Builder<K, V>

Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation or the most recent replacement of its value.

When duration is zero, the cache's max size will be set to 0 meaning no values will be cached.

+
abstract fun expireAfterWrite(duration: Duration): Cache.Builder<K, V>

Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation or the most recent replacement of its value.

When duration is zero, the cache's max size will be set to 0 meaning no values will be cached.

- +
-
+

Builder

-
interface Builder<K : Any, V : Any>

Main entry point for creating a Cache.

+
interface Builder<K : Any, V : Any>

Main entry point for creating a Cache.

Types

-
-
+
+
- +
Link copied to clipboard
-
object Companion
+
object Companion
@@ -88,92 +88,92 @@

Types

Functions

-
-
+
+
- +
Link copied to clipboard
-
abstract fun build(): Cache<K, V>

Builds a new instance of Cache with the specified configurations.

+
abstract fun build(): Cache<K, V>

Builds a new instance of Cache with the specified configurations.

- -
+ +
- +
Link copied to clipboard
-
abstract fun eventListener(listener: CacheEventListener<K, V>): Cache.Builder<K, V>

Specifies a CacheEventListener to be used to handle cache events.

+
abstract fun eventListener(listener: CacheEventListener<K, V>): Cache.Builder<K, V>

Specifies a CacheEventListener to be used to handle cache events.

- -
+ +
- +
Link copied to clipboard
-
abstract fun expireAfterAccess(duration: Duration): Cache.Builder<K, V>

Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, the most recent replacement of its value, or its last access.

+
abstract fun expireAfterAccess(duration: Duration): Cache.Builder<K, V>

Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation, the most recent replacement of its value, or its last access.

- -
+ +
- +
Link copied to clipboard
-
abstract fun expireAfterWrite(duration: Duration): Cache.Builder<K, V>

Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation or the most recent replacement of its value.

+
abstract fun expireAfterWrite(duration: Duration): Cache.Builder<K, V>

Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after the entry's creation or the most recent replacement of its value.

- -
+ +
- +
Link copied to clipboard
-
abstract fun maximumCacheSize(size: Long): Cache.Builder<K, V>

Specifies the maximum number of entries the cache may contain. Cache eviction policy is based on LRU - i.e. least recently accessed entries get evicted first.

+
abstract fun maximumCacheSize(size: Long): Cache.Builder<K, V>

Specifies the maximum number of entries the cache may contain. Cache eviction policy is based on LRU - i.e. least recently accessed entries get evicted first.

- -
+ +
- +
Link copied to clipboard
-
abstract fun timeSource(timeSource: TimeSource): Cache.Builder<K, V>

Specifies a TimeSource to be used for expiry checks. If not specified, TimeSource.Monotonic will be used.

+
abstract fun timeSource(timeSource: TimeSource): Cache.Builder<K, V>

Specifies a TimeSource to be used for expiry checks. If not specified, TimeSource.Monotonic will be used.

diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache/-builder/maximum-cache-size.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache/-builder/maximum-cache-size.html index 2d1f91d..32982b0 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache/-builder/maximum-cache-size.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache/-builder/maximum-cache-size.html @@ -45,7 +45,7 @@
- +
-
+

maximumCacheSize

-
abstract fun maximumCacheSize(size: Long): Cache.Builder<K, V>

Specifies the maximum number of entries the cache may contain. Cache eviction policy is based on LRU - i.e. least recently accessed entries get evicted first.

When size is 0, entries will be discarded immediately and no values will be cached.

If not set, cache size will be unlimited.

+
abstract fun maximumCacheSize(size: Long): Cache.Builder<K, V>

Specifies the maximum number of entries the cache may contain. Cache eviction policy is based on LRU - i.e. least recently accessed entries get evicted first.

When size is 0, entries will be discarded immediately and no values will be cached.

If not set, cache size will be unlimited.

- +
-
+

timeSource

-
abstract fun timeSource(timeSource: TimeSource): Cache.Builder<K, V>

Specifies a TimeSource to be used for expiry checks. If not specified, TimeSource.Monotonic will be used.

+
abstract fun timeSource(timeSource: TimeSource): Cache.Builder<K, V>

Specifies a TimeSource to be used for expiry checks. If not specified, TimeSource.Monotonic will be used.

- +
-
+

asMap

-
abstract fun asMap(): Map<in Key, Value>

Returns a defensive copy of cache entries as Map.

+
abstract fun asMap(): Map<in Key, Value>

Returns a defensive copy of cache entries as Map.

- +
-
+

get

-
abstract fun get(key: Key): Value?

Returns the value associated with key in this cache, or null if there is no cached value for key.


abstract suspend fun get(key: Key, loader: suspend () -> Value): Value

Returns the value associated with key in this cache if exists, otherwise gets the value by invoking loader, associates the value with key in the cache, and returns the cached value.

Any exceptions thrown by the loader will be propagated to the caller of this function.

+
abstract fun get(key: Key): Value?

Returns the value associated with key in this cache, or null if there is no cached value for key.


abstract suspend fun get(key: Key, loader: suspend () -> Value): Value

Returns the value associated with key in this cache if exists, otherwise gets the value by invoking loader, associates the value with key in the cache, and returns the cached value.

Any exceptions thrown by the loader will be propagated to the caller of this function.

- +
-
+

Cache

-
interface Cache<in Key : Any, Value : Any>

An in-memory key-value cache with support for time-based (expiration) and size-based evictions.

+
interface Cache<in Key : Any, Value : Any>

An in-memory key-value cache with support for time-based (expiration) and size-based evictions.

Types

-
-
+
+
- +
Link copied to clipboard
-
interface Builder<K : Any, V : Any>

Main entry point for creating a Cache.

+
interface Builder<K : Any, V : Any>

Main entry point for creating a Cache.

@@ -88,77 +88,77 @@

Types

Functions

-
-
+
+
- +
Link copied to clipboard
-
abstract fun asMap(): Map<in Key, Value>

Returns a defensive copy of cache entries as Map.

+
abstract fun asMap(): Map<in Key, Value>

Returns a defensive copy of cache entries as Map.

- -
+ +
- +
Link copied to clipboard
-
abstract fun get(key: Key): Value?

Returns the value associated with key in this cache, or null if there is no cached value for key.

abstract suspend fun get(key: Key, loader: suspend () -> Value): Value

Returns the value associated with key in this cache if exists, otherwise gets the value by invoking loader, associates the value with key in the cache, and returns the cached value.

+
abstract fun get(key: Key): Value?

Returns the value associated with key in this cache, or null if there is no cached value for key.

abstract suspend fun get(key: Key, loader: suspend () -> Value): Value

Returns the value associated with key in this cache if exists, otherwise gets the value by invoking loader, associates the value with key in the cache, and returns the cached value.

- -
+ +
- +
Link copied to clipboard
-
abstract fun invalidate(key: Key)

Discards any cached value for key key.

+
abstract fun invalidate(key: Key)

Discards any cached value for key key.

- -
+ +
- +
Link copied to clipboard
-
abstract fun invalidateAll()

Discards all entries in the cache.

+
abstract fun invalidateAll()

Discards all entries in the cache.

- -
+ +
- +
Link copied to clipboard
-
abstract fun put(key: Key, value: Value)

Associates value with key in this cache. If the cache previously contained a value associated with key, the old value is replaced by value.

+
abstract fun put(key: Key, value: Value)

Associates value with key in this cache. If the cache previously contained a value associated with key, the old value is replaced by value.

diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-cache/invalidate-all.html b/api/cache4k/io.github.reactivecircus.cache4k/-cache/invalidate-all.html index b4bd9ad..31c56aa 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-cache/invalidate-all.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-cache/invalidate-all.html @@ -45,7 +45,7 @@
- +
-
+

invalidateAll

-
abstract fun invalidateAll()

Discards all entries in the cache.

+
abstract fun invalidateAll()

Discards all entries in the cache.

- +
-
+

invalidate

-
abstract fun invalidate(key: Key)

Discards any cached value for key key.

+
abstract fun invalidate(key: Key)

Discards any cached value for key key.

- +
-
+

put

-
abstract fun put(key: Key, value: Value)

Associates value with key in this cache. If the cache previously contained a value associated with key, the old value is replaced by value.

+
abstract fun put(key: Key, value: Value)

Associates value with key in this cache. If the cache previously contained a value associated with key, the old value is replaced by value.

- +
-
+

FakeTimeSource

-
constructor()
+
constructor()
- +
-
+

FakeTimeSource

-

A time source that has programmatically updatable readings with support for multi-threaded access in Kotlin/Native.

Implementation is identical to kotlin.time.TestTimeSource except the internal reading is an AtomicLong.

+

A time source that has programmatically updatable readings with support for multi-threaded access in Kotlin/Native.

Implementation is identical to kotlin.time.TestTimeSource except the internal reading is an AtomicLong.

Constructors

-
-
+
+
- +
Link copied to clipboard
-
constructor()
+
constructor()
@@ -88,32 +88,32 @@

Constructors

Functions

-
-
+
+
- - + +
Link copied to clipboard
-
open override fun markNow(): ComparableTimeMark
+
open override fun markNow(): ComparableTimeMark
- -
+ +
- +
Link copied to clipboard
-
operator fun plusAssign(duration: Duration)

Advances the current reading value of this time source by the specified duration.

+
operator fun plusAssign(duration: Duration)

Advances the current reading value of this time source by the specified duration.

diff --git a/api/cache4k/io.github.reactivecircus.cache4k/-fake-time-source/plus-assign.html b/api/cache4k/io.github.reactivecircus.cache4k/-fake-time-source/plus-assign.html index 4cded5b..b6ffa0a 100644 --- a/api/cache4k/io.github.reactivecircus.cache4k/-fake-time-source/plus-assign.html +++ b/api/cache4k/io.github.reactivecircus.cache4k/-fake-time-source/plus-assign.html @@ -45,7 +45,7 @@
- +
-
+

plusAssign

-
operator fun plusAssign(duration: Duration)

Advances the current reading value of this time source by the specified duration.

duration value is rounded down towards zero when converting it to a Long number of nanoseconds. For example, if the duration being added is 0.6.nanoseconds, the reading doesn't advance because the duration value is rounded to zero nanoseconds.

Throws

when the reading value overflows as the result of this operation.

+
operator fun plusAssign(duration: Duration)

Advances the current reading value of this time source by the specified duration.

duration value is rounded down towards zero when converting it to a Long number of nanoseconds. For example, if the duration being added is 0.6.nanoseconds, the reading doesn't advance because the duration value is rounded to zero nanoseconds.

Throws

when the reading value overflows as the result of this operation.

- +
-
+

Package-level declarations

@@ -68,62 +68,62 @@

Package-level declaratio

Types

-
-
+
+
- +
Link copied to clipboard
-
interface Cache<in Key : Any, Value : Any>

An in-memory key-value cache with support for time-based (expiration) and size-based evictions.

+
interface Cache<in Key : Any, Value : Any>

An in-memory key-value cache with support for time-based (expiration) and size-based evictions.

- -
+ +
- +
Link copied to clipboard
-
interface CacheEvent<Key : Any, Value : Any>

An event resulting from a mutative Cache operation.

+
interface CacheEvent<Key : Any, Value : Any>

An event resulting from a mutative Cache operation.

- -
+ +
- +
Link copied to clipboard
-
fun interface CacheEventListener<Key : Any, Value : Any>

Definition of the contract for implementing listeners to receive CacheEvents from a Cache.

+
fun interface CacheEventListener<Key : Any, Value : Any>

Definition of the contract for implementing listeners to receive CacheEvents from a Cache.

- -
+ +
- +
Link copied to clipboard
-

A time source that has programmatically updatable readings with support for multi-threaded access in Kotlin/Native.

+

A time source that has programmatically updatable readings with support for multi-threaded access in Kotlin/Native.

diff --git a/api/cache4k/navigation.html b/api/cache4k/navigation.html index 1df7e8b..3ca796b 100644 --- a/api/cache4k/navigation.html +++ b/api/cache4k/navigation.html @@ -1,63 +1,63 @@
-
+
-
+
-
+
-
+ -
+
-
+ -
+ -
+ -
+ - -
+ -
+
diff --git a/api/navigation.html b/api/navigation.html index eb2d307..c988248 100644 --- a/api/navigation.html +++ b/api/navigation.html @@ -1,63 +1,63 @@
-
+
-
+
-
+
-
+ -
+
-
+ -
+ -
+ -
+ - -
+ -
+
diff --git a/api/scripts/sourceset_dependencies.js b/api/scripts/sourceset_dependencies.js index e8866b7..c114951 100644 --- a/api/scripts/sourceset_dependencies.js +++ b/api/scripts/sourceset_dependencies.js @@ -1 +1 @@ -sourceset_dependencies = '{":cache4k:dokkaHtmlPartial/appleMain":[":cache4k:dokkaHtmlPartial/nativeMain",":cache4k:dokkaHtmlPartial/nonJvm"],":cache4k:dokkaHtmlPartial/commonMain":[],":cache4k:dokkaHtmlPartial/iosArm64Main":[":cache4k:dokkaHtmlPartial/iosMain"],":cache4k:dokkaHtmlPartial/iosMain":[":cache4k:dokkaHtmlPartial/appleMain",":cache4k:dokkaHtmlPartial/jvmAndIos"],":cache4k:dokkaHtmlPartial/iosSimulatorArm64Main":[":cache4k:dokkaHtmlPartial/iosMain"],":cache4k:dokkaHtmlPartial/iosX64Main":[":cache4k:dokkaHtmlPartial/iosMain"],":cache4k:dokkaHtmlPartial/jsMain":[":cache4k:dokkaHtmlPartial/commonMain",":cache4k:dokkaHtmlPartial/nonJvm"],":cache4k:dokkaHtmlPartial/jvmAndIos":[":cache4k:dokkaHtmlPartial/commonMain"],":cache4k:dokkaHtmlPartial/jvmMain":[":cache4k:dokkaHtmlPartial/commonMain",":cache4k:dokkaHtmlPartial/jvmAndIos"],":cache4k:dokkaHtmlPartial/linuxArm64Main":[":cache4k:dokkaHtmlPartial/linuxMain"],":cache4k:dokkaHtmlPartial/linuxMain":[":cache4k:dokkaHtmlPartial/nativeMain",":cache4k:dokkaHtmlPartial/nonJvm"],":cache4k:dokkaHtmlPartial/linuxX64Main":[":cache4k:dokkaHtmlPartial/linuxMain"],":cache4k:dokkaHtmlPartial/macosArm64Main":[":cache4k:dokkaHtmlPartial/macosMain"],":cache4k:dokkaHtmlPartial/macosMain":[":cache4k:dokkaHtmlPartial/appleMain"],":cache4k:dokkaHtmlPartial/macosX64Main":[":cache4k:dokkaHtmlPartial/macosMain"],":cache4k:dokkaHtmlPartial/mingwMain":[":cache4k:dokkaHtmlPartial/nativeMain",":cache4k:dokkaHtmlPartial/nonJvm"],":cache4k:dokkaHtmlPartial/mingwX64Main":[":cache4k:dokkaHtmlPartial/mingwMain"],":cache4k:dokkaHtmlPartial/nativeMain":[":cache4k:dokkaHtmlPartial/commonMain"],":cache4k:dokkaHtmlPartial/nonJvm":[":cache4k:dokkaHtmlPartial/commonMain"],":cache4k:dokkaHtmlPartial/tvosArm64Main":[":cache4k:dokkaHtmlPartial/tvosMain"],":cache4k:dokkaHtmlPartial/tvosMain":[":cache4k:dokkaHtmlPartial/appleMain"],":cache4k:dokkaHtmlPartial/tvosSimulatorArm64Main":[":cache4k:dokkaHtmlPartial/tvosMain"],":cache4k:dokkaHtmlPartial/tvosX64Main":[":cache4k:dokkaHtmlPartial/tvosMain"],":cache4k:dokkaHtmlPartial/wasmJsMain":[":cache4k:dokkaHtmlPartial/commonMain",":cache4k:dokkaHtmlPartial/nonJvm"],":cache4k:dokkaHtmlPartial/watchosArm64Main":[":cache4k:dokkaHtmlPartial/watchosMain"],":cache4k:dokkaHtmlPartial/watchosMain":[":cache4k:dokkaHtmlPartial/appleMain"],":cache4k:dokkaHtmlPartial/watchosSimulatorArm64Main":[":cache4k:dokkaHtmlPartial/watchosMain"],":cache4k:dokkaHtmlPartial/watchosX64Main":[":cache4k:dokkaHtmlPartial/watchosMain"]}' \ No newline at end of file +sourceset_dependencies = '{":cache4k:dokkaHtmlPartial/appleMain":[":cache4k:dokkaHtmlPartial/nativeMain",":cache4k:dokkaHtmlPartial/nonJvmMain"],":cache4k:dokkaHtmlPartial/commonMain":[],":cache4k:dokkaHtmlPartial/iosArm64Main":[":cache4k:dokkaHtmlPartial/iosMain"],":cache4k:dokkaHtmlPartial/iosMain":[":cache4k:dokkaHtmlPartial/appleMain"],":cache4k:dokkaHtmlPartial/iosSimulatorArm64Main":[":cache4k:dokkaHtmlPartial/iosMain"],":cache4k:dokkaHtmlPartial/iosX64Main":[":cache4k:dokkaHtmlPartial/iosMain"],":cache4k:dokkaHtmlPartial/jsMain":[":cache4k:dokkaHtmlPartial/commonMain",":cache4k:dokkaHtmlPartial/nonJvmMain"],":cache4k:dokkaHtmlPartial/jvmMain":[":cache4k:dokkaHtmlPartial/commonMain"],":cache4k:dokkaHtmlPartial/linuxArm64Main":[":cache4k:dokkaHtmlPartial/linuxMain"],":cache4k:dokkaHtmlPartial/linuxMain":[":cache4k:dokkaHtmlPartial/nativeMain",":cache4k:dokkaHtmlPartial/nonJvmMain"],":cache4k:dokkaHtmlPartial/linuxX64Main":[":cache4k:dokkaHtmlPartial/linuxMain"],":cache4k:dokkaHtmlPartial/macosArm64Main":[":cache4k:dokkaHtmlPartial/macosMain"],":cache4k:dokkaHtmlPartial/macosMain":[":cache4k:dokkaHtmlPartial/appleMain"],":cache4k:dokkaHtmlPartial/macosX64Main":[":cache4k:dokkaHtmlPartial/macosMain"],":cache4k:dokkaHtmlPartial/mingwMain":[":cache4k:dokkaHtmlPartial/nativeMain",":cache4k:dokkaHtmlPartial/nonJvmMain"],":cache4k:dokkaHtmlPartial/mingwX64Main":[":cache4k:dokkaHtmlPartial/mingwMain"],":cache4k:dokkaHtmlPartial/nativeMain":[":cache4k:dokkaHtmlPartial/commonMain"],":cache4k:dokkaHtmlPartial/nonJvmMain":[":cache4k:dokkaHtmlPartial/commonMain"],":cache4k:dokkaHtmlPartial/tvosArm64Main":[":cache4k:dokkaHtmlPartial/tvosMain"],":cache4k:dokkaHtmlPartial/tvosMain":[":cache4k:dokkaHtmlPartial/appleMain"],":cache4k:dokkaHtmlPartial/tvosSimulatorArm64Main":[":cache4k:dokkaHtmlPartial/tvosMain"],":cache4k:dokkaHtmlPartial/tvosX64Main":[":cache4k:dokkaHtmlPartial/tvosMain"],":cache4k:dokkaHtmlPartial/wasmJsMain":[":cache4k:dokkaHtmlPartial/commonMain",":cache4k:dokkaHtmlPartial/nonJvmMain"],":cache4k:dokkaHtmlPartial/watchosArm64Main":[":cache4k:dokkaHtmlPartial/watchosMain"],":cache4k:dokkaHtmlPartial/watchosMain":[":cache4k:dokkaHtmlPartial/appleMain"],":cache4k:dokkaHtmlPartial/watchosSimulatorArm64Main":[":cache4k:dokkaHtmlPartial/watchosMain"],":cache4k:dokkaHtmlPartial/watchosX64Main":[":cache4k:dokkaHtmlPartial/watchosMain"]}' \ No newline at end of file diff --git a/changelog/index.html b/changelog/index.html index 13f6008..aa9b629 100644 --- a/changelog/index.html +++ b/changelog/index.html @@ -1 +1 @@ - Change Log - cache4k

Change Log

0.12.0

Added

Added new targets: - linuxArm64

Changed

  • Kotlin 1.9.10
  • Coroutines 1.7.2
  • AtomicFU 0.21.0
  • Stately 2.0.5

0.11.0

Added

  • New event listener APIs (@darkxanter) - 35

Fixed

  • Downgrade stately to 1.2.5 to fix duplicate class error - 36

0.10.0

Added

Added new targets: - watchosArm64 - watchosSimulatorArm64 - watchosX64

FakeTimeSource is now public - #30

Changed

  • Kotlin 1.8.20.
  • AtomicFU 0.20.2.
  • Stately 2.0.0-rc1.

0.9.0

Fixed

  • Revert to using state-collections to fix JVM concurrency issue - #23

Changed

  • Kotlin 1.7.20.
  • AtomicFU 0.18.5.

0.8.0

Added

Added new targets: - linuxX64 - macosArm64

Changed

  • Kotlin 1.7.10.
  • Coroutines 1.6.4.
  • AtomicFU 0.18.3.

0.7.0

Changed

  • Kotlin 1.7.0.
  • Coroutines 1.6.3.
  • AtomicFU 0.18.2.

0.6.0

Changed

  • fakeTimeSource in Cache.Builder has been renamed to timeSource, and the FakeTimeSource implementation has been removed (still available in our tests) - #20
  • Kotlin 1.6.21.

0.5.0

This release adds support for new native memory model and drops support for the old one. Many thanks to @dcvz for the contribution.

Added

  • Synchronize cache loader by key - #15
  • Support new native memory model and drop support for old memory model - #17

Changed

  • Kotlin 1.6.20.
  • Coroutines 1.6.1.

0.4.0

Added

Added new targets: - iosSimulatorArm64 - macosArm64 - tvosArm64 - tvosSimulatorArm64 - tvosX64

Changed

  • Kotlin 1.6.10.
  • Stately 1.2.1.
  • Target Java 11.

0.3.0

Changed

  • Change fun newBuilder() to operator fun invoke() - #7.
  • Compile with Kotlin 1.5.21.

0.2.0

Changed

  • Support Kotlin 1.5.0.
  • Stately to 1.1.7.

0.1.1

Changed

  • Disable IR.

0.1.0

Initial release.

\ No newline at end of file + Change Log - cache4k

Change Log

0.13.0

Added

Added new targets: - wasmJs - #45

Changed

  • Switch internal map implementation to ConcurrentHashMap for JVM targets - #39
  • Kotlin 1.9.22
  • Coroutines 1.8.0
  • AtomicFU 0.23.2
  • Stately 2.0.6

0.12.0

Added

Added new targets: - linuxArm64

Changed

  • Kotlin 1.9.10
  • Coroutines 1.7.2
  • AtomicFU 0.21.0
  • Stately 2.0.5

0.11.0

Added

  • New event listener APIs (@darkxanter) - #35

Fixed

  • Downgrade stately to 1.2.5 to fix duplicate class error - #36

0.10.0

Added

Added new targets: - watchosArm64 - watchosSimulatorArm64 - watchosX64

FakeTimeSource is now public - #30

Changed

  • Kotlin 1.8.20.
  • AtomicFU 0.20.2.
  • Stately 2.0.0-rc1.

0.9.0

Fixed

  • Revert to using state-collections to fix JVM concurrency issue - #23

Changed

  • Kotlin 1.7.20.
  • AtomicFU 0.18.5.

0.8.0

Added

Added new targets: - linuxX64 - macosArm64

Changed

  • Kotlin 1.7.10.
  • Coroutines 1.6.4.
  • AtomicFU 0.18.3.

0.7.0

Changed

  • Kotlin 1.7.0.
  • Coroutines 1.6.3.
  • AtomicFU 0.18.2.

0.6.0

Changed

  • fakeTimeSource in Cache.Builder has been renamed to timeSource, and the FakeTimeSource implementation has been removed (still available in our tests) - #20
  • Kotlin 1.6.21.

0.5.0

This release adds support for new native memory model and drops support for the old one. Many thanks to @dcvz for the contribution.

Added

  • Synchronize cache loader by key - #15
  • Support new native memory model and drop support for old memory model - #17

Changed

  • Kotlin 1.6.20.
  • Coroutines 1.6.1.

0.4.0

Added

Added new targets: - iosSimulatorArm64 - macosArm64 - tvosArm64 - tvosSimulatorArm64 - tvosX64

Changed

  • Kotlin 1.6.10.
  • Stately 1.2.1.
  • Target Java 11.

0.3.0

Changed

  • Change fun newBuilder() to operator fun invoke() - #7.
  • Compile with Kotlin 1.5.21.

0.2.0

Changed

  • Support Kotlin 1.5.0.
  • Stately to 1.1.7.

0.1.1

Changed

  • Disable IR.

0.1.0

Initial release.

\ No newline at end of file diff --git a/search/search_index.json b/search/search_index.json index b004405..1e9a115 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"cache4k","text":"

In-memory Cache for Kotlin Multiplatform.

Work in progress.

cache4k provides a simple in-memory key-value cache for Kotlin Multiplatform, with support for time-based (expiration) and size-based evictions.

Note that only the new Kotlin Native memory model is supported.

The following targets are currently supported:

  • jvm
  • js
  • wasmJs
  • iosX64
  • iosArm64
  • iosSimulatorArm64
  • macosX64
  • macosArm64
  • tvosX64
  • tvosArm64
  • tvosSimulatorArm64
  • watchosX64
  • watchosArm64
  • watchosSimulatorArm64
  • linuxX64
  • linuxArm64
  • mingwX64
"},{"location":"#download","title":"Download","text":"

Dependencies are hosted on Maven Central.

"},{"location":"#android","title":"Android","text":"
dependencies {\n    implementation(\"io.github.reactivecircus.cache4k:cache4k:x.y.z\")\n}\n
"},{"location":"#multiplatform","title":"Multiplatform","text":"
kotlin {\n    sourceSets {\n        commonMain {\n            dependencies {\n                implementation(\"io.github.reactivecircus.cache4k:cache4k:x.y.z\")\n            }\n        }\n    }\n}\n
"},{"location":"#usage","title":"Usage","text":""},{"location":"#writing-and-reading-cache-entries","title":"Writing and reading cache entries","text":"

To create a new Cache instance using Long for the key and String for the value:

val cache = Cache.Builder<Long, String>().build()\n

To start writing entries to the cache:

cache.put(1, \"dog\")\ncache.put(2, \"cat\")\n

To read a cache entry by key:

cache.get(1) // returns \"dog\"\ncache.get(2) // returns \"cat\"\ncache.get(3) // returns null\n

To overwrite an existing cache entry:

cache.put(1, \"dog\")\ncache.put(1, \"bird\")\ncache.get(1) // returns \"bird\"\n
"},{"location":"#cache-loader","title":"Cache loader","text":"

Cache provides an API for getting cached value by key and using the provided loader: suspend () -> Value lambda to compute and cache the value automatically if none exists.

runBlockingTest {\n    val cache = Cache.Builder<Long, User>().build()\n\n    val userId = 1L\n    val user = cache.get(userId) {\n        fetchUserById(userId) // potentially expensive call (might be a suspend function)\n    }\n\n    // value successfully computed by the loader will be cached automatically\n    assertThat(user).isEqualTo(cache.get(userId))\n}\n

Note that loader is executed on the caller\u2019s coroutine context. Concurrent calls from multiple threads using the same key will be blocked. Assuming the 1st call successfully computes a new value, none of the loader from the other calls will be executed and the cached value computed by the first loader will be returned for those calls.

Any exceptions thrown by the loader will be propagated to the caller of this function.

"},{"location":"#expirations-and-evictions","title":"Expirations and evictions","text":"

By default, Cache has an unlimited number of entries which never expire. But a cache can be configured to support both time-based expirations and size-based evictions.

"},{"location":"#time-based-expiration","title":"Time-based expiration","text":"

Expiration time can be specified for entries in the cache.

"},{"location":"#expire-after-access","title":"Expire after access","text":"

To set the maximum time an entry can live in the cache since the last access (also known as ** time-to-idle**), where \u201caccess\u201d means reading the cache, adding a new cache entry, or ** replacing an existing entry with a new one**:

val cache = Cache.Builder<Long, String>()\n    .expireAfterAccess(24.hours)\n    .build()\n

An entry in this cache will be removed if it has not been read or replaced after 24 hours since it\u2019s been written into the cache.

"},{"location":"#expire-after-write","title":"Expire after write","text":"

To set the maximum time an entry can live in the cache since the last write (also known as ** time-to-live**), where \u201cwrite\u201d means adding a new cache entry or replacing an existing entry with a new one:

val cache = Cache.Builder<Long, String>()\n    .expireAfterWrite(30.minutes)\n    .build()\n

An entry in this cache will be removed if it has not been replaced after 30 minutes since it\u2019s been written into the cache.

Note that cache entries are not removed immediately upon expiration at exact time. Expirations are checked in each interaction with the cache.

"},{"location":"#size-based-eviction","title":"Size-based eviction","text":"

To set the maximum number of entries to be kept in the cache:

val cache = Cache.Builder<Long, String>()\n    .maximumCacheSize(100)\n    .build()\n

Once there are more than 100 entries in this cache, the least recently used one will be removed, where \u201cused\u201d means reading the cache, adding a new cache entry, or replacing an existing entry with a new one.

"},{"location":"#getting-all-cache-entries-as-a-map","title":"Getting all cache entries as a Map","text":"

To get a copy of the current cache entries as a Map:

val cache = Cache.Builder<Long, String>()\n    .build()\n\ncache.put(1, \"dog\")\ncache.put(2, \"cat\")\n\nassertThat(cache.asMap())\n    .isEqualTo(mapOf(1L to \"dog\", 2L to \"cat\"))\n

Note that calling asMap() has no effect on the access expiry of the cache.

"},{"location":"#deleting-cache-entries","title":"Deleting cache entries","text":"

Cache entries can also be deleted explicitly.

To delete a cache entry for a given key:

val cache = Cache.Builder<Long, String>().build()\ncache.put(1, \"dog\")\n\ncache.invalidate(1)\n\nassertThat(cache.get(1)).isNull()\n

To delete all entries in the cache:

cache.invalidateAll()\n
"},{"location":"#event-listener","title":"Event listener","text":"

You can set an event listener as a lambda:

val cache1 = Cache.Builder<Long, String>()\n    .eventListener { event ->\n        println(\"onEvent: $event\")\n    }\n    .build()\n

Or declare it as a class and share logic across many stores:

class FileDeleteEventListener : CacheEventListener<Long, File> {\n    override fun onEvent(event: CacheEvent<Long, File>) {\n        when(event) {\n            is CacheEvent.Created -> {}\n            is CacheEvent.Updated -> event.oldValue.delete()\n            is CacheEvent.Evicted -> event.value.delete()\n            is CacheEvent.Expired -> event.value.delete()\n            is CacheEvent.Removed -> event.value.delete()\n        }\n    }\n}\nval fileDeleteEventListener = FileDeleteEventListener()\n\nval cache1 = Cache.Builder<Long, File>()\n    .eventListener(fileDeleteEventListener)\n    .build()\n\nval cache2 = Cache.Builder<Long, File>()\n    .eventListener(fileDeleteEventListener)\n    .build()\n

Cache entry event firing behaviors for mutative methods:

Initial value Operation New value Event {} put(K, V) {K: V} Created(K, V) {K: V1} put(K, V2) {K: V2} Updated(K, V1, V2) {K: V} invalidate(K) {} Removed(K, V) {K1: V1, K2: V2} invalidateAll() {} Removed(K1, V1), Removed(K2, V2) {K: V} any operation, K expired {} Expired(K, V) {K1: V1} put(K2, V2), K1 evicted {K2: V2} Created(K2, V2), Evicted(K1, V1)"},{"location":"#unit-testing-cache-expirations","title":"Unit testing cache expirations","text":"

To test logic that depends on cache expiration, pass in a FakeTimeSource when building a Cache so you can programmatically advance the reading of the time source:

@Test\nfun cacheEntryEvictedAfterExpiration() {\n    private val fakeTimeSource = FakeTimeSource()\n    val cache = Cache.Builder<Long, String>()\n        .timeSource(fakeTimeSource)\n        .expireAfterWrite(1.minutes)\n        .build()\n\n    cache.put(1, \"dog\")\n\n    // just before expiry\n    fakeTimeSource += 1.minutes - 1.nanoseconds\n\n    assertThat(cache.get(1))\n        .isEqualTo(\"dog\")\n\n    // now expires\n    fakeTimeSource += 1.nanoseconds\n\n    assertThat(cache.get(1))\n        .isNull()\n}\n
"},{"location":"#credits","title":"Credits","text":"

The library was ported from a kotlin / JVM cache which I contributed to dropbox/Store to help unblock Store\u2019s multiplatform support ( it was reverted before the 1.0 release as multiplatform wasn\u2019t a priority). Many thanks to Store\u2019s owners and contributors for reviewing and improving the original implementation.

"},{"location":"#license","title":"License","text":"
Copyright 2021 Yang Chen\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n

YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit is the creator of YourKit Java Profiler, YourKit .NET Profiler, and YourKit YouMonitor.

"},{"location":"changelog/","title":"Change Log","text":""},{"location":"changelog/#0120","title":"0.12.0","text":""},{"location":"changelog/#added","title":"Added","text":"

Added new targets: - linuxArm64

"},{"location":"changelog/#changed","title":"Changed","text":"
  • Kotlin 1.9.10
  • Coroutines 1.7.2
  • AtomicFU 0.21.0
  • Stately 2.0.5
"},{"location":"changelog/#0110","title":"0.11.0","text":""},{"location":"changelog/#added_1","title":"Added","text":"
  • New event listener APIs (@darkxanter) - 35
"},{"location":"changelog/#fixed","title":"Fixed","text":"
  • Downgrade stately to 1.2.5 to fix duplicate class error - 36
"},{"location":"changelog/#0100","title":"0.10.0","text":""},{"location":"changelog/#added_2","title":"Added","text":"

Added new targets: - watchosArm64 - watchosSimulatorArm64 - watchosX64

FakeTimeSource is now public - #30

"},{"location":"changelog/#changed_1","title":"Changed","text":"
  • Kotlin 1.8.20.
  • AtomicFU 0.20.2.
  • Stately 2.0.0-rc1.
"},{"location":"changelog/#090","title":"0.9.0","text":""},{"location":"changelog/#fixed_1","title":"Fixed","text":"
  • Revert to using state-collections to fix JVM concurrency issue - #23
"},{"location":"changelog/#changed_2","title":"Changed","text":"
  • Kotlin 1.7.20.
  • AtomicFU 0.18.5.
"},{"location":"changelog/#080","title":"0.8.0","text":""},{"location":"changelog/#added_3","title":"Added","text":"

Added new targets: - linuxX64 - macosArm64

"},{"location":"changelog/#changed_3","title":"Changed","text":"
  • Kotlin 1.7.10.
  • Coroutines 1.6.4.
  • AtomicFU 0.18.3.
"},{"location":"changelog/#070","title":"0.7.0","text":""},{"location":"changelog/#changed_4","title":"Changed","text":"
  • Kotlin 1.7.0.
  • Coroutines 1.6.3.
  • AtomicFU 0.18.2.
"},{"location":"changelog/#060","title":"0.6.0","text":""},{"location":"changelog/#changed_5","title":"Changed","text":"
  • fakeTimeSource in Cache.Builder has been renamed to timeSource, and the FakeTimeSource implementation has been removed (still available in our tests) - #20
  • Kotlin 1.6.21.
"},{"location":"changelog/#050","title":"0.5.0","text":"

This release adds support for new native memory model and drops support for the old one. Many thanks to @dcvz for the contribution.

"},{"location":"changelog/#added_4","title":"Added","text":"
  • Synchronize cache loader by key - #15
  • Support new native memory model and drop support for old memory model - #17
"},{"location":"changelog/#changed_6","title":"Changed","text":"
  • Kotlin 1.6.20.
  • Coroutines 1.6.1.
"},{"location":"changelog/#040","title":"0.4.0","text":""},{"location":"changelog/#added_5","title":"Added","text":"

Added new targets: - iosSimulatorArm64 - macosArm64 - tvosArm64 - tvosSimulatorArm64 - tvosX64

"},{"location":"changelog/#changed_7","title":"Changed","text":"
  • Kotlin 1.6.10.
  • Stately 1.2.1.
  • Target Java 11.
"},{"location":"changelog/#030","title":"0.3.0","text":""},{"location":"changelog/#changed_8","title":"Changed","text":"
  • Change fun newBuilder() to operator fun invoke() - #7.
  • Compile with Kotlin 1.5.21.
"},{"location":"changelog/#020","title":"0.2.0","text":""},{"location":"changelog/#changed_9","title":"Changed","text":"
  • Support Kotlin 1.5.0.
  • Stately to 1.1.7.
"},{"location":"changelog/#011","title":"0.1.1","text":""},{"location":"changelog/#changed_10","title":"Changed","text":"
  • Disable IR.
"},{"location":"changelog/#010","title":"0.1.0","text":"

Initial release.

"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"cache4k","text":"

In-memory Cache for Kotlin Multiplatform.

Work in progress.

cache4k provides a simple in-memory key-value cache for Kotlin Multiplatform, with support for time-based (expiration) and size-based evictions.

Note that only the new Kotlin Native memory model is supported.

The following targets are currently supported:

  • jvm
  • js
  • wasmJs
  • iosX64
  • iosArm64
  • iosSimulatorArm64
  • macosX64
  • macosArm64
  • tvosX64
  • tvosArm64
  • tvosSimulatorArm64
  • watchosX64
  • watchosArm64
  • watchosSimulatorArm64
  • linuxX64
  • linuxArm64
  • mingwX64
"},{"location":"#download","title":"Download","text":"

Dependencies are hosted on Maven Central.

"},{"location":"#android","title":"Android","text":"
dependencies {\n    implementation(\"io.github.reactivecircus.cache4k:cache4k:x.y.z\")\n}\n
"},{"location":"#multiplatform","title":"Multiplatform","text":"
kotlin {\n    sourceSets {\n        commonMain {\n            dependencies {\n                implementation(\"io.github.reactivecircus.cache4k:cache4k:x.y.z\")\n            }\n        }\n    }\n}\n
"},{"location":"#usage","title":"Usage","text":""},{"location":"#writing-and-reading-cache-entries","title":"Writing and reading cache entries","text":"

To create a new Cache instance using Long for the key and String for the value:

val cache = Cache.Builder<Long, String>().build()\n

To start writing entries to the cache:

cache.put(1, \"dog\")\ncache.put(2, \"cat\")\n

To read a cache entry by key:

cache.get(1) // returns \"dog\"\ncache.get(2) // returns \"cat\"\ncache.get(3) // returns null\n

To overwrite an existing cache entry:

cache.put(1, \"dog\")\ncache.put(1, \"bird\")\ncache.get(1) // returns \"bird\"\n
"},{"location":"#cache-loader","title":"Cache loader","text":"

Cache provides an API for getting cached value by key and using the provided loader: suspend () -> Value lambda to compute and cache the value automatically if none exists.

runBlockingTest {\n    val cache = Cache.Builder<Long, User>().build()\n\n    val userId = 1L\n    val user = cache.get(userId) {\n        fetchUserById(userId) // potentially expensive call (might be a suspend function)\n    }\n\n    // value successfully computed by the loader will be cached automatically\n    assertThat(user).isEqualTo(cache.get(userId))\n}\n

Note that loader is executed on the caller\u2019s coroutine context. Concurrent calls from multiple threads using the same key will be blocked. Assuming the 1st call successfully computes a new value, none of the loader from the other calls will be executed and the cached value computed by the first loader will be returned for those calls.

Any exceptions thrown by the loader will be propagated to the caller of this function.

"},{"location":"#expirations-and-evictions","title":"Expirations and evictions","text":"

By default, Cache has an unlimited number of entries which never expire. But a cache can be configured to support both time-based expirations and size-based evictions.

"},{"location":"#time-based-expiration","title":"Time-based expiration","text":"

Expiration time can be specified for entries in the cache.

"},{"location":"#expire-after-access","title":"Expire after access","text":"

To set the maximum time an entry can live in the cache since the last access (also known as ** time-to-idle**), where \u201caccess\u201d means reading the cache, adding a new cache entry, or ** replacing an existing entry with a new one**:

val cache = Cache.Builder<Long, String>()\n    .expireAfterAccess(24.hours)\n    .build()\n

An entry in this cache will be removed if it has not been read or replaced after 24 hours since it\u2019s been written into the cache.

"},{"location":"#expire-after-write","title":"Expire after write","text":"

To set the maximum time an entry can live in the cache since the last write (also known as ** time-to-live**), where \u201cwrite\u201d means adding a new cache entry or replacing an existing entry with a new one:

val cache = Cache.Builder<Long, String>()\n    .expireAfterWrite(30.minutes)\n    .build()\n

An entry in this cache will be removed if it has not been replaced after 30 minutes since it\u2019s been written into the cache.

Note that cache entries are not removed immediately upon expiration at exact time. Expirations are checked in each interaction with the cache.

"},{"location":"#size-based-eviction","title":"Size-based eviction","text":"

To set the maximum number of entries to be kept in the cache:

val cache = Cache.Builder<Long, String>()\n    .maximumCacheSize(100)\n    .build()\n

Once there are more than 100 entries in this cache, the least recently used one will be removed, where \u201cused\u201d means reading the cache, adding a new cache entry, or replacing an existing entry with a new one.

"},{"location":"#getting-all-cache-entries-as-a-map","title":"Getting all cache entries as a Map","text":"

To get a copy of the current cache entries as a Map:

val cache = Cache.Builder<Long, String>()\n    .build()\n\ncache.put(1, \"dog\")\ncache.put(2, \"cat\")\n\nassertThat(cache.asMap())\n    .isEqualTo(mapOf(1L to \"dog\", 2L to \"cat\"))\n

Note that calling asMap() has no effect on the access expiry of the cache.

"},{"location":"#deleting-cache-entries","title":"Deleting cache entries","text":"

Cache entries can also be deleted explicitly.

To delete a cache entry for a given key:

val cache = Cache.Builder<Long, String>().build()\ncache.put(1, \"dog\")\n\ncache.invalidate(1)\n\nassertThat(cache.get(1)).isNull()\n

To delete all entries in the cache:

cache.invalidateAll()\n
"},{"location":"#event-listener","title":"Event listener","text":"

You can set an event listener as a lambda:

val cache1 = Cache.Builder<Long, String>()\n    .eventListener { event ->\n        println(\"onEvent: $event\")\n    }\n    .build()\n

Or declare it as a class and share logic across many stores:

class FileDeleteEventListener : CacheEventListener<Long, File> {\n    override fun onEvent(event: CacheEvent<Long, File>) {\n        when(event) {\n            is CacheEvent.Created -> {}\n            is CacheEvent.Updated -> event.oldValue.delete()\n            is CacheEvent.Evicted -> event.value.delete()\n            is CacheEvent.Expired -> event.value.delete()\n            is CacheEvent.Removed -> event.value.delete()\n        }\n    }\n}\nval fileDeleteEventListener = FileDeleteEventListener()\n\nval cache1 = Cache.Builder<Long, File>()\n    .eventListener(fileDeleteEventListener)\n    .build()\n\nval cache2 = Cache.Builder<Long, File>()\n    .eventListener(fileDeleteEventListener)\n    .build()\n

Cache entry event firing behaviors for mutative methods:

Initial value Operation New value Event {} put(K, V) {K: V} Created(K, V) {K: V1} put(K, V2) {K: V2} Updated(K, V1, V2) {K: V} invalidate(K) {} Removed(K, V) {K1: V1, K2: V2} invalidateAll() {} Removed(K1, V1), Removed(K2, V2) {K: V} any operation, K expired {} Expired(K, V) {K1: V1} put(K2, V2), K1 evicted {K2: V2} Created(K2, V2), Evicted(K1, V1)"},{"location":"#unit-testing-cache-expirations","title":"Unit testing cache expirations","text":"

To test logic that depends on cache expiration, pass in a FakeTimeSource when building a Cache so you can programmatically advance the reading of the time source:

@Test\nfun cacheEntryEvictedAfterExpiration() {\n    private val fakeTimeSource = FakeTimeSource()\n    val cache = Cache.Builder<Long, String>()\n        .timeSource(fakeTimeSource)\n        .expireAfterWrite(1.minutes)\n        .build()\n\n    cache.put(1, \"dog\")\n\n    // just before expiry\n    fakeTimeSource += 1.minutes - 1.nanoseconds\n\n    assertThat(cache.get(1))\n        .isEqualTo(\"dog\")\n\n    // now expires\n    fakeTimeSource += 1.nanoseconds\n\n    assertThat(cache.get(1))\n        .isNull()\n}\n
"},{"location":"#credits","title":"Credits","text":"

The library was ported from a kotlin / JVM cache which I contributed to dropbox/Store to help unblock Store\u2019s multiplatform support ( it was reverted before the 1.0 release as multiplatform wasn\u2019t a priority). Many thanks to Store\u2019s owners and contributors for reviewing and improving the original implementation.

"},{"location":"#license","title":"License","text":"
Copyright 2021 Yang Chen\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n

YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit is the creator of YourKit Java Profiler, YourKit .NET Profiler, and YourKit YouMonitor.

"},{"location":"changelog/","title":"Change Log","text":""},{"location":"changelog/#0130","title":"0.13.0","text":""},{"location":"changelog/#added","title":"Added","text":"

Added new targets: - wasmJs - #45

"},{"location":"changelog/#changed","title":"Changed","text":"
  • Switch internal map implementation to ConcurrentHashMap for JVM targets - #39
  • Kotlin 1.9.22
  • Coroutines 1.8.0
  • AtomicFU 0.23.2
  • Stately 2.0.6
"},{"location":"changelog/#0120","title":"0.12.0","text":""},{"location":"changelog/#added_1","title":"Added","text":"

Added new targets: - linuxArm64

"},{"location":"changelog/#changed_1","title":"Changed","text":"
  • Kotlin 1.9.10
  • Coroutines 1.7.2
  • AtomicFU 0.21.0
  • Stately 2.0.5
"},{"location":"changelog/#0110","title":"0.11.0","text":""},{"location":"changelog/#added_2","title":"Added","text":"
  • New event listener APIs (@darkxanter) - #35
"},{"location":"changelog/#fixed","title":"Fixed","text":"
  • Downgrade stately to 1.2.5 to fix duplicate class error - #36
"},{"location":"changelog/#0100","title":"0.10.0","text":""},{"location":"changelog/#added_3","title":"Added","text":"

Added new targets: - watchosArm64 - watchosSimulatorArm64 - watchosX64

FakeTimeSource is now public - #30

"},{"location":"changelog/#changed_2","title":"Changed","text":"
  • Kotlin 1.8.20.
  • AtomicFU 0.20.2.
  • Stately 2.0.0-rc1.
"},{"location":"changelog/#090","title":"0.9.0","text":""},{"location":"changelog/#fixed_1","title":"Fixed","text":"
  • Revert to using state-collections to fix JVM concurrency issue - #23
"},{"location":"changelog/#changed_3","title":"Changed","text":"
  • Kotlin 1.7.20.
  • AtomicFU 0.18.5.
"},{"location":"changelog/#080","title":"0.8.0","text":""},{"location":"changelog/#added_4","title":"Added","text":"

Added new targets: - linuxX64 - macosArm64

"},{"location":"changelog/#changed_4","title":"Changed","text":"
  • Kotlin 1.7.10.
  • Coroutines 1.6.4.
  • AtomicFU 0.18.3.
"},{"location":"changelog/#070","title":"0.7.0","text":""},{"location":"changelog/#changed_5","title":"Changed","text":"
  • Kotlin 1.7.0.
  • Coroutines 1.6.3.
  • AtomicFU 0.18.2.
"},{"location":"changelog/#060","title":"0.6.0","text":""},{"location":"changelog/#changed_6","title":"Changed","text":"
  • fakeTimeSource in Cache.Builder has been renamed to timeSource, and the FakeTimeSource implementation has been removed (still available in our tests) - #20
  • Kotlin 1.6.21.
"},{"location":"changelog/#050","title":"0.5.0","text":"

This release adds support for new native memory model and drops support for the old one. Many thanks to @dcvz for the contribution.

"},{"location":"changelog/#added_5","title":"Added","text":"
  • Synchronize cache loader by key - #15
  • Support new native memory model and drop support for old memory model - #17
"},{"location":"changelog/#changed_7","title":"Changed","text":"
  • Kotlin 1.6.20.
  • Coroutines 1.6.1.
"},{"location":"changelog/#040","title":"0.4.0","text":""},{"location":"changelog/#added_6","title":"Added","text":"

Added new targets: - iosSimulatorArm64 - macosArm64 - tvosArm64 - tvosSimulatorArm64 - tvosX64

"},{"location":"changelog/#changed_8","title":"Changed","text":"
  • Kotlin 1.6.10.
  • Stately 1.2.1.
  • Target Java 11.
"},{"location":"changelog/#030","title":"0.3.0","text":""},{"location":"changelog/#changed_9","title":"Changed","text":"
  • Change fun newBuilder() to operator fun invoke() - #7.
  • Compile with Kotlin 1.5.21.
"},{"location":"changelog/#020","title":"0.2.0","text":""},{"location":"changelog/#changed_10","title":"Changed","text":"
  • Support Kotlin 1.5.0.
  • Stately to 1.1.7.
"},{"location":"changelog/#011","title":"0.1.1","text":""},{"location":"changelog/#changed_11","title":"Changed","text":"
  • Disable IR.
"},{"location":"changelog/#010","title":"0.1.0","text":"

Initial release.

"}]} \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index a5f5695..4ede6cb 100644 Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ