Table of Contents

Interface ITcgDexResponseCache

Namespace
TcgDex.Caching
Assembly
TcgDex.CSharpSdk.dll

Stores API responses so repeated reads avoid the network.

public interface ITcgDexResponseCache

Remarks

Implement this to back the cache with something shared or persistent — Redis, a distributed cache, or disk. The default is in-memory and per-process. Implementations must be safe for concurrent use.

Methods

GetAsync(string, CancellationToken)

Retrieves an entry, or null if absent.

ValueTask<CachedResponse?> GetAsync(string key, CancellationToken cancellationToken = default)

Parameters

key string

The cache key, derived from the request URI.

cancellationToken CancellationToken

Cancels the lookup.

Returns

ValueTask<CachedResponse?>

The cached response, or null.

RemoveAsync(string, CancellationToken)

Removes an entry, if present.

ValueTask RemoveAsync(string key, CancellationToken cancellationToken = default)

Parameters

key string

The cache key.

cancellationToken CancellationToken

Cancels the removal.

Returns

ValueTask

A task that completes when the entry is gone.

SetAsync(string, CachedResponse, TimeSpan, CancellationToken)

Stores an entry.

ValueTask SetAsync(string key, CachedResponse response, TimeSpan timeToLive, CancellationToken cancellationToken = default)

Parameters

key string

The cache key.

response CachedResponse

The response to store.

timeToLive TimeSpan

How long it may be served before revalidation.

cancellationToken CancellationToken

Cancels the write.

Returns

ValueTask

A task that completes when the entry is stored.