suparnatural-cache / com.suparnatural.core.cache / Cacheable


interface Cacheable

Any object which should be cached must be Cacheable. Each cache object must have a unique identifier returned by cacheKey. If the object wishes to be persistable, then the serializeForPersistence method can return a string which represents its serialized version.


Make any object ready for caching.

class Person(val name: String, val id: String): Cacheable {
    // return the unique id as the cache key.
    fun cacheKey() = id

    // persist a json string.
    fun serializeForPersistence() = Json.nonstrict.stringify(..., this)



abstract fun cacheKey(): String

Returns the unique key used to identify the object in the cache.


abstract fun serializeForPersistence(): String

Returns a serialized string which can be persisted. If this is the last object returned by the preprocessor chain, the return value of this method will be persisted as it is. Otherwise, this method will not called.



data class RawCacheable : Cacheable

A container to hold raw version for a cached object read from a persistent store. For example, in case of a disk store, key is the file name and value is the file contents. This is the first Cacheable object passed to the preprocessor chain. Therefore, your first preprocessor should expect RawCacheable as the input to CacheStorePreprocessor.unarchive method.


class TombStoneMarker : Cacheable

A marker which replaces deleted objects. If the space is marked as null after deletion, then it leaves other objects with same hash codes unreachable. Search continues if the current cell has a TombStoneMarker.