StateViewCaches

class StateViewCaches(factory: CoCacheFactory, queries: () -> QueryApi)

The state view caches of a service, one CoCache cache per aggregate type, each holding that type's states as the view StateView marks, each at the aggregate's version: what a StateViewCache reads, and what the owner's StateViewWriter writes after each commit.

Everything about a cache follows from its view, the same on the owner and on every reader (specOf):

  • its name is wow.<context>.<aggregate> (nameOf), the aggregate the view's @StateView names;

  • its key is the aggregate's StateKey, stored as <tenantId>/<id>;

  • its value is the view, stored as its JSON (StateViewCodec), at the aggregate's version: a versioned cache, so a state is written only over an older one, and a deleted aggregate is a tombstone at its version that no older state undoes;

  • a miss is read from the owner through the node's typed queries (queries): in process when the node serves the aggregate, else over HTTP as this service, the queries pinned to the key's tenant; a batch read is one query per tenant, its ids in one IN. The fill holds CoCache's lease, which the owner's write takes over: a fill never puts back a state older than the owner's. An aggregate never created is cached as absent (CoCache's negative cache).

  • no early refresh (refreshWindow = off()): the owner writes every version after its commit, so a refresh would only read the owner again, over HTTP on a reader. The declaration keeps CoCache's global cocache.defaults.cache.refresh-window off these caches; cocache.caches.[wow.<context>.<aggregate>].refresh-window still turns it on for one.

Each cache is created once, by factory: CoCache's starter's (its CoCacheFactory bean), which applies the application's CoCache settings to it (cocache.defaults.cache.*, cocache.overrides.cache.*, cocache.caches.[wow.<context>.<aggregate>].*), else one on the runtime alone, which applies none.

Constructors

Link copied to clipboard
constructor(factory: CoCacheFactory, queries: () -> QueryApi)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun declare(viewTypes: Collection<Class<*>>)

Creates the caches of viewTypes now: CoCache's starter checks its settings against the caches it knows.

Link copied to clipboard
inline fun <reified V : Any> of(): StateViewCache<V>

The cache of the states V views, created on first use.

fun <V : Any> of(viewType: Class<V>): StateViewCache<V>

The cache of the states viewType views, created on first use.

Link copied to clipboard
fun <V : Any> writerOf(viewType: Class<V>, ttl: Duration? = null): StateViewWriter<V>

The writer of the states viewType views, each written for ttl, else for the cache's lifetime.