suparnatural-cache / com.suparnatural.core.cache / CacheStoreWorker

CacheStoreWorker

interface CacheStoreWorker

A CacheStore schedules its operations (controlled by CacheStore.blocking parameter) on a CacheStoreWorker. Workers are expected to operate in a single mode (blocking/non-blocking). Therefore, each worker can assume the mode in which it will be invoked in and should schedule all of its tasks (with exceptions) in that mode forever.

Workers should always operate with a non-capturing lambda meaning, all the state outside of the invocation context of a worker should be considered invisible to a worker task.

Examples

Non capturing task

class MyBackgroundWorker: CacheStoreWorker {
    fun persistObject(input..., task...) {
        myHandlerBasedScheduler.execute {
            task(input)
        }
    }


}

Functions

persistObject

abstract fun <T : Cacheable> persistObject(input: <ERROR CLASS><T, <ERROR CLASS>, List<CacheStorePreprocessor<Cacheable, Cacheable, Cacheable>>?>, task: (<ERROR CLASS><T, <ERROR CLASS>, List<CacheStorePreprocessor<Cacheable, Cacheable, Cacheable>>?>) -> Unit): Unit

Invokes a strictly non-capturing lambda task with the input as an argument to persist T. The task must not access any state other than its arguments including any immutable of frozen objects to guarantee thread safety.

terminate

abstract fun terminate(): <ERROR CLASS><Unit>

Close all resource handles and terminate the worker.

unlinkObject

abstract fun unlinkObject(input: <ERROR CLASS>, task: (<ERROR CLASS>) -> Unit): Unit

Invokes a strictly non-capturing lambda task with input to delete an object located at input. The task must not access any state other than its arguments including any immutable of frozen objects to guarantee thread safety.

Inheritors

CacheStoreBlockingWorker

class CacheStoreBlockingWorker : CacheStoreWorker

A CacheStoreWorker which blocks the calling thread.

CacheStoreNonBlockingWorker

class CacheStoreNonBlockingWorker : CacheStoreWorker

A background worker for the cache store which does not block the calling thread. The calling thread cannot wait for the result. Therefore, this worker is supposed to be used in a fire and forget scenario. Otherwise, use CacheStoreBlockingWorker.