Table of Contents

Interface ICacheCoordinator

Namespace
CL.MySQL2.Services
Assembly
CL.MySQL2.dll

Cross-node coordination for the query cache. The default (NullCacheCoordinator) is single-node and does nothing; a distributed adapter (Redis pub/sub, NATS, etc.) is supplied by the consumer via UseCoordinator(ICacheCoordinator) — exactly the same plug-in model as ICacheStore. The library ships no transport dependency of its own.

Two responsibilities:

  1. Invalidation fan-outPublishInvalidationAsync(string, CancellationToken) broadcasts a local table mutation so peers drop their cached entries. Without this, each process keeps its own per-table version counter and a mutation on one node never invalidates the others.
  2. Single-flight refreshTryAcquireRefreshLeaseAsync(string, TimeSpan, CancellationToken) lets exactly one node own a SmartCachePool's refresh each tick, so N nodes don't all hit the database. This assumes a shared ICacheStore (e.g. Redis): the lease holder refreshes and writes; the others read the shared entry.
public interface ICacheCoordinator : IAsyncDisposable
Inherited Members

Methods

OnInvalidation(Action<string>)

Registers a handler invoked when a peer broadcasts an invalidation. The handler bumps the local table version and evicts matching entries (it must NOT re-broadcast — that would loop). Called once when the coordinator is installed.

void OnInvalidation(Action<string> handler)

Parameters

handler Action<string>

PublishInvalidationAsync(string, CancellationToken)

Broadcasts that tableName was mutated on this node so peers can invalidate their cached entries for it. Fire-and-forget from the caller's perspective; implementations should not throw on transient transport failures.

Task PublishInvalidationAsync(string tableName, CancellationToken ct = default)

Parameters

tableName string
ct CancellationToken

Returns

Task

TryAcquireRefreshLeaseAsync(string, TimeSpan, CancellationToken)

Attempts to acquire the refresh lease for poolName for the next lease window. Returns true if this node should perform the refresh, false if a peer already holds it. The single-node default always returns true.

Task<bool> TryAcquireRefreshLeaseAsync(string poolName, TimeSpan lease, CancellationToken ct = default)

Parameters

poolName string
lease TimeSpan
ct CancellationToken

Returns

Task<bool>