abstract class InMemoryCache : Cache
An abstract, thread-safe in-memory cache with a custom HashTable implementation backed by an array of atomic values. It guarantees consistency in both single and multi-threaded environment.
InMemoryCache(size: Int, persistentStores: List<CacheStore> = emptyList(), replacementPolicy: CacheReplacementPolicy)
An abstract, thread-safe in-memory cache with a custom HashTable implementation backed by an array of atomic values. It guarantees consistency in both single and multi-threaded environment. |
val lock: <ERROR CLASS>
A read write lock for thread safety. |
|
open val persistentStores: List<CacheStore>
List of persistent stores backing cache. |
|
open val replacementPolicy: CacheReplacementPolicy
Cache replacement policy to create space when cache is full. |
|
open val size: Int
Size of the cache |
fun <T : Cacheable> addObject(obj: CacheableContainer): Boolean
Adds an object to persistent store. Assumes that lock is already obtained. |
|
open fun getAllObjects(): List<Cacheable>
Returns a list of all the cached objects. |
|
open fun hashCode(key: String): Int
Returns a hash code for the given key. For example, it may wrap the raw hash code for a string by cache sizeUnsafe. |
|
open fun rehydrate(): Unit
Rehydrates the cache by loading all the cached objects from the persisted stores. It does a total replacement of current cache with the objects loaded from persistent stores and does not perform a merge of any sort. |
|
fun <T : Cacheable> removeObject(obj: CacheableContainer): <ERROR CLASS><T?, Boolean>
Removes the item from persistent stores. Assumes that lock is already obtained. |
abstract fun <T : Cacheable> addObject(obj: T): Boolean
Adds a Cacheable object to the cache. The cache key is retrieved by calling Cacheable.cacheKey method. |
|
abstract fun <T : Cacheable> getObject(key: String): T?
Returns a object with the given key. |
|
abstract fun <T : Cacheable> removeObject(key: String): <ERROR CLASS><T?, Boolean>
Removed a Cacheable object from the cache. |
class LinearProbingCache : InMemoryCache
A thread-safe InMemoryCache with a custom HashTable implementation based on Linear Probing. |
|
class RobinHoodProbingCache : InMemoryCache
A thread-safe InMemoryCache with a custom HashTable implementation using Robin Hood hashing. |