InMemoryKache
An in-memory coroutine-safe versatile cache that stores objects by keys.
It can be built using the following syntax:
val cache = InMemoryKache<String, String>(maxSize = 100) {
strategy = KacheStrategy.LRU
// ...
}See also
Types
Configuration for InMemoryKache. It is used as a receiver of InMemoryKache builder
Properties
The max size of this cache in units calculated by SizeCalculator of the cache. This represents the max number of entries if SizeCalculator used the default implementation (returning 1 for each entry),
The current size of this cache in units calculated by SizeCalculator of the cache. This represents the current number of entries if SizeCalculator used the default implementation (returning 1 for each entry),
Functions
Clears the cache, calling EntryRemovedListener on each removed entry with evicted set to false.
Evicts all entries, calling EntryRemovedListener on each removed entry with evicted set to true.
Removes all expired entries, calling EntryRemovedListener on each removed entry with evicted set to true.
Returns a KacheKeys instance that represents the keys that are currently in the cache, along with those that are under creation.
Returns the value for key if it exists in the cache or null if it doesn't exist or its creation is still in progress.
Returns the value for key if it exists in the cache or defaultValue if it doesn't exist or its creation is still in progress.
Returns the value for key if it exists in the cache or waits for its creation if it is currently in progress. This returns defaultValue if a value is neither cached nor under creation or cannot be created.
Returns the value for key if it exists in the cache, its creation is in progress, or it can be created by creationFunction. This returns null if a value is not cached and cannot be created. You can imply that the creation has failed by returning null. Any unhandled exceptions inside creationFunction won't be handled.
Returns a set of the keys that are currently under creation.
Caches value for key. If there is a previous value or in-progress creation, it will be replaced/cancelled. It returns the previous value if it already exists, or null if it doesn't exist or its creation is still in progress.
Creates a new entry for key using creationFunction and returns the new value. Any existing value or in-progress creation of key would be replaced by the new function. This returns null if the value cannot be created. You can imply that the creation has failed by returning null. Any unhandled exceptions inside creationFunction won't be handled.
Creates a new entry for key using creationFunction and returns a Deferred. Any existing value or in-progress creation of key would be replaced by the new function. You can imply that the creation has failed by returning null.
Cancels all in-progress creations.
Remove entries according to the policy defined by strategy until the total of remaining entries is/at/or below size. It won't affect the max size of the cache, allowing it to grow again.