Table of Contents

Class LastSeenCacheTracker<TKey, TValue>

Namespace
FishMMO.Auth.Core.Collections
Assembly
FishMMO-ServerAuth.dll

Queue/index tracker for key-value caches whose entries expire by last-seen timestamp. Optimized for high-frequency touch and bounded head-first TTL sweeps.

public sealed class LastSeenCacheTracker<TKey, TValue>

Type Parameters

TKey

Cache key type.

TValue

Cache value type.

Inheritance
LastSeenCacheTracker<TKey, TValue>
Inherited Members

Constructors

LastSeenCacheTracker(IEqualityComparer<TKey>?)

Initializes a new tracker with an optional key comparer.

public LastSeenCacheTracker(IEqualityComparer<TKey>? comparer = null)

Parameters

comparer IEqualityComparer<TKey>

Methods

Clear()

Clears all cached entries.

public void Clear()

Remove(TKey)

Removes a cached key if present.

public void Remove(TKey key)

Parameters

key TKey

The cache key to remove.

SweepExpired(DateTime, TimeSpan, int, int)

Sweeps entries whose last-seen exceeds the provided TTL.

public int SweepExpired(DateTime nowUtc, TimeSpan ttl, int maxScan, int maxRemove)

Parameters

nowUtc DateTime

Current UTC time.

ttl TimeSpan

Maximum age before an entry is swept.

maxScan int

Maximum number of entries to inspect per sweep.

maxRemove int

Maximum number of entries to remove per sweep.

Returns

int

Number of entries removed.

TryGetAndTouch(TKey, DateTime, out TValue)

Tries to get a cached value and refreshes its last-seen timestamp.

public bool TryGetAndTouch(TKey key, DateTime nowUtc, out TValue value)

Parameters

key TKey

The cache key to look up.

nowUtc DateTime

Current UTC time; used to update the last-seen timestamp.

value TValue

The cached value if found; otherwise, default.

Returns

bool

true if the key was found; otherwise, false.

Upsert(TKey, TValue, DateTime)

Inserts or updates a cached value and sets its last-seen timestamp.

public void Upsert(TKey key, TValue value, DateTime nowUtc)

Parameters

key TKey

The cache key.

value TValue

The value to store.

nowUtc DateTime

Current UTC time used as the last-seen timestamp.