CacheOrchestrator<K, V> class final

A sequential layered cache: L1 (memory) → L2 (optional) → L3 (optional).

On read: checks each layer in order. The first hit is returned and promoted into all faster layers above it (write-back on hit).

On write: writes to all configured layers.

On miss across all layers: returns null. Fetching from the network is the caller's responsibility — use CacheRepositoryMixin for that.

Example

final cache = CacheOrchestrator<String, Product>(
  l1: MemoryCache(maxEntries: 100),
  l3: DiskCache(codec: const JsonCacheCodec(fromJson: Product.fromJson)),
);

await cache.put('p_1', product);
final p = await cache.get('p_1'); // L1 hit — no disk access
await cache.dispose();
Implemented types

Constructors

CacheOrchestrator({required Cache<K, V> l1, Cache<K, V>? l2, Cache<K, V>? l3})
Creates a CacheOrchestrator.

Properties

hashCode int
The hash code for this object.
no setterinherited
l1 Cache<K, V>
L1 — fastest layer, always required. Typically a MemoryCache.
final
l2 Cache<K, V>?
L2 — optional middle layer. Typically a SecureCache.
final
l3 Cache<K, V>?
L3 — optional persistence layer. Typically a DiskCache.
final
metrics CacheMetrics
Metrics from the L1 (memory) layer.
no setteroverride
metricsStream Stream<CacheMetrics>
Metrics stream from the L1 (memory) layer.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clear() Future<void>
Removes all entries from this cache.
override
containsKey(K key) Future<bool>
Returns true if key is present and not expired.
override
dispose() Future<void>
Releases all resources held by this cache: sweep timers, stream controllers, file handles, and pending writes.
override
get(K key) Future<V?>
Returns the cached value for key, or null if absent or expired.
override
getResult(K key) Future<CacheResult<V>>
Returns a CacheResult for key:
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(K key, V value, {Duration? ttl}) Future<void>
Stores value under key.
override
putAll(Map<K, V> entries, {Duration? ttl}) Future<void>
Stores all entries from entries.
override
remove(K key) Future<void>
Removes the entry for key. No-op if the key is not present.
override
removeWhere(bool test(K key, V value)) Future<void>
Removes all entries for which test returns true.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited