LayeredCache

class LayeredCache<V : Any>(memory: Cache<V>, persistent: Cache<V>? = null) : Cache<V>

A two-tier cache composing a fast memory layer over an optional persistent layer.

Mirrors SwiftyNetwork's LayeredCache: reads consult memory first, fall back to the persistent layer, and promote a persistent hit back into memory — preserving the original timestamp when the memory layer is a TimestampedCache. Writes go through to both layers.

changes reflects writes and removals against this layered view; read-time promotions are not reported, since the logical value did not change.

Parameters

memory

the fast, volatile layer.

persistent

the durable layer, or null for a memory-only cache.

Constructors

Link copied to clipboard
constructor(memory: Cache<V>, persistent: Cache<V>? = null)

Functions

Link copied to clipboard
open override fun changes(): Flow<CacheChange>

A hot stream of CacheChanges for this cache. The default is an empty flow, so caches that cannot observe mutations are simply non-reactive; observable caches override this.

Link copied to clipboard
open suspend override fun entry(key: CacheKey): CacheEntry<V>?

Atomically returns the value and its timestamp for key, or null if absent.

Link copied to clipboard
open suspend override fun removeAll()

Removes every entry.

Link copied to clipboard
open suspend override fun removeValue(key: CacheKey)

Removes any value stored for key.

Link copied to clipboard
open suspend override fun setValue(value: V, key: CacheKey)

Stores value for key, stamping it with the current time.

Link copied to clipboard
open suspend override fun timestamp(key: CacheKey): Long?

Returns the epoch-millisecond timestamp recorded for key, or null if absent.

Link copied to clipboard
open suspend override fun value(key: CacheKey): V?

Returns the value stored for key, or null if absent.