suparnatural-cache / com.suparnatural.core.cache / RobinHoodProbingCache

RobinHoodProbingCache

class RobinHoodProbingCache : InMemoryCache

A thread-safe InMemoryCache with a custom HashTable implementation using Robin Hood hashing.

Types

Quintuple

data class Quintuple<A, B, C, D>

A class representing a group of four values

Constructors

<init>

RobinHoodProbingCache(size: Int, persistentStores: List<CacheStore> = emptyList(), replacementPolicy: CacheReplacementPolicy = FifoCacheReplacementPolicy(size))

A thread-safe InMemoryCache with a custom HashTable implementation using Robin Hood hashing.

Inherited Properties

lock

val lock: <ERROR CLASS>

A read write lock for thread safety.

persistentStores

open val persistentStores: List<CacheStore>

List of persistent stores backing cache.

replacementPolicy

open val replacementPolicy: CacheReplacementPolicy

Cache replacement policy to create space when cache is full.

size

open val size: Int

Size of the cache

Functions

addObject

fun <T : Cacheable> addObject(obj: T): Boolean

Adds a Cacheable object to the cache. The cache key is retrieved by calling Cacheable.cacheKey method.

getObject

fun <T : Cacheable> getObject(key: String): T?

Returns a object with the given key.

removeObject

fun <T : Cacheable> removeObject(key: String): <ERROR CLASS><T?, Boolean>

Inherited Functions

addObject

fun <T : Cacheable> addObject(obj: CacheableContainer): Boolean

Adds an object to persistent store. Assumes that lock is already obtained.

getAllObjects

open fun getAllObjects(): List<Cacheable>

Returns a list of all the cached objects.

hashCode

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.

rehydrate

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.

removeObject

fun <T : Cacheable> removeObject(obj: CacheableContainer): <ERROR CLASS><T?, Boolean>

Removes the item from persistent stores. Assumes that lock is already obtained.