Class MemoryTcgDexResponseCache
- Namespace
- TcgDex.Caching
- Assembly
- TcgDex.CSharpSdk.dll
The default in-process response cache: bounded, thread-safe, and evicting the least recently used entries when full.
public sealed class MemoryTcgDexResponseCache : ITcgDexResponseCacheInheritance
Implements
Inherited Members
Remarks
Deliberately not built on IMemoryCache. That would add a package
reference for a dictionary with an eviction policy, and it prices entries by
an arbitrary "size" unit; here the natural bound is a count of responses,
which is directly meaningful.
Eviction tracks last access rather than insertion, so the entries an application actually reads survive — which for this API means the enumeration endpoints it hits on every screen. The bounding and eviction policy itself lives in TcgDex.Caching.BoundedLru`2, shared with the deserialized-response cache; what this type adds is the absolute lifetime.
Constructors
MemoryTcgDexResponseCache(int, TimeProvider?)
Creates a cache holding at most maxEntries responses.
public MemoryTcgDexResponseCache(int maxEntries = 512, TimeProvider? timeProvider = null)Parameters
maxEntriesint-
The upper bound on stored entries.
timeProviderTimeProvider?-
Clock used for expiry; defaults to the system clock.
Exceptions
- ArgumentOutOfRangeException
-
maxEntriesis less than one.
Properties
Count
The number of entries currently held.
public int Count { get; }Property Value
Methods
Clear()
Empties the cache.
public void Clear()GetAsync(string, CancellationToken)
Retrieves an entry, or null if absent.
public ValueTask<CachedResponse?> GetAsync(string key, CancellationToken cancellationToken = default)Parameters
keystring-
The cache key, derived from the request URI.
cancellationTokenCancellationToken-
Cancels the lookup.
Returns
- ValueTask<CachedResponse?>
-
The cached response, or null.
RemoveAsync(string, CancellationToken)
Removes an entry, if present.
public ValueTask RemoveAsync(string key, CancellationToken cancellationToken = default)Parameters
keystring-
The cache key.
cancellationTokenCancellationToken-
Cancels the removal.
Returns
- ValueTask
-
A task that completes when the entry is gone.
SetAsync(string, CachedResponse, TimeSpan, CancellationToken)
Stores an entry.
public ValueTask SetAsync(string key, CachedResponse response, TimeSpan timeToLive, CancellationToken cancellationToken = default)Parameters
keystring-
The cache key.
responseCachedResponse-
The response to store.
timeToLiveTimeSpan-
How long it may be served before revalidation.
cancellationTokenCancellationToken-
Cancels the write.
Returns
- ValueTask
-
A task that completes when the entry is stored.