Table of Contents

Class SmartCachePool

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

A named group of cached queries that is kept warm by a background timer. Queries opt in via .SmartCache("poolName"); on first execution they register their refresh factory with the pool. Every RefreshEvery the pool re-runs every registered factory and overwrites the cache entry, so subsequent reads never block on the DB. Entries stay warm forever once registered — the pool never evicts them.

public sealed class SmartCachePool : IAsyncDisposable
Inheritance
SmartCachePool
Implements
Inherited Members

Properties

MaxIdleFires

Drop an entry after this many consecutive refresh ticks with no read. Default 10.

public int MaxIdleFires { get; }

Property Value

int

Name

Pool name used by .SmartCache(name). Case-insensitive.

public string Name { get; }

Property Value

string

RefreshEvery

How often the pool re-runs every registered factory.

public TimeSpan RefreshEvery { get; }

Property Value

TimeSpan

Methods

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

GetStats()

Snapshot of pool stats for diagnostics.

public SmartCachePoolStats GetStats()

Returns

SmartCachePoolStats

HasEntriesForTable(string)

Returns true if this pool has any active refresh entries for the given table name. Used to suppress mutation-triggered cache invalidation for tables whose freshness is managed by the pool's background refresh.

public bool HasEntriesForTable(string tableName)

Parameters

tableName string

Returns

bool

RefreshNowAsync(CancellationToken)

Runs every registered factory once. Public so callers can warm the pool on startup (or trigger an out-of-schedule refresh after a deploy).

public Task RefreshNowAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task

WarmUp(Func<Task>)

Runs warmUp as a fire-and-forget task so the pool's hot queries are populated before any user request hits them. Inside warmUp, just call the queries that should be warm (with their normal .SmartCache(...) decoration) — they auto-register with this pool as they always do.

Exceptions are caught and logged so a slow or broken warm-up never crashes startup. The pool stays lazy if the warm-up fails: queries still register on their first real read.

public void WarmUp(Func<Task> warmUp)

Parameters

warmUp Func<Task>