Table of Contents

Class InMemoryCacheTagTracker

Namespace
Excalibur.Dispatch.Caching
Assembly
Excalibur.Dispatch.Caching.dll

In-process implementation of ICacheTagTracker using a bounded ConcurrentDictionary<TKey, TValue> of per-tag version stamps. Thread-safe for single-process scenarios (Memory cache mode, or Distributed/Hybrid mode where cross-instance tag propagation is not required).

public sealed class InMemoryCacheTagTracker : ICacheTagTracker
Inheritance
InMemoryCacheTagTracker
Implements
Inherited Members
Extension Methods

Constructors

InMemoryCacheTagTracker()

Initializes a new instance of the InMemoryCacheTagTracker class.

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Meter lifecycle is managed by the class instance; instruments hold a reference to it")]
public InMemoryCacheTagTracker()

InMemoryCacheTagTracker(IMeterFactory)

Initializes a new instance of the InMemoryCacheTagTracker class using an IMeterFactory.

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Meter lifecycle is managed by IMeterFactory; instruments hold a reference to it")]
public InMemoryCacheTagTracker(IMeterFactory meterFactory)

Parameters

meterFactory IMeterFactory

The meter factory for DI-managed meter lifecycle.

InMemoryCacheTagTracker(IMeterFactory, IOptions<CacheOptions>, ILogger<InMemoryCacheTagTracker>?)

Initializes a new instance of the InMemoryCacheTagTracker class with bounded capacity.

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "Meter lifecycle is managed by IMeterFactory; instruments hold a reference to it")]
public InMemoryCacheTagTracker(IMeterFactory meterFactory, IOptions<CacheOptions> options, ILogger<InMemoryCacheTagTracker>? logger = null)

Parameters

meterFactory IMeterFactory

The meter factory for DI-managed meter lifecycle.

options IOptions<CacheOptions>

Cache options providing TagTrackerCapacity.

logger ILogger<InMemoryCacheTagTracker>

Optional logger for capacity warnings.

Methods

BumpStampAsync(string, CancellationToken)

Invalidates a tag by replacing its current version stamp with a new one.

public Task BumpStampAsync(string tag, CancellationToken cancellationToken)

Parameters

tag string

The tag to invalidate.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task

A task that completes once the tag's stamp has been replaced.

Remarks

Every cache entry that recorded the tag's previous stamp stops matching on its next read and is treated as invalidated. This does not delete or enumerate any cache entry; stale entries are discovered lazily, on their next read, and evicted at that point.

GetOrCreateStampAsync(string, CancellationToken)

Gets the current version stamp for a tag, creating one if the tag has never been observed before.

public Task<string> GetOrCreateStampAsync(string tag, CancellationToken cancellationToken)

Parameters

tag string

The tag to resolve a version stamp for.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<string>

A task that resolves to the tag's current version stamp: an opaque string that changes only when the tag is invalidated via BumpStampAsync(string, CancellationToken). The returned value carries no meaning beyond equality comparison and must never be parsed, ordered, or compared for recency — only for equality against a previously recorded stamp.

Remarks

Called both when writing a new cache entry (to embed the tag's stamp at write time) and when reading an existing entry (to compare against the stamp it recorded at write time). A well behaved implementation memoizes the in-flight resolution per tag so that concurrent callers for the same tag collapse onto a single backend round trip rather than each starting their own.