Table of Contents

Class TcgDexCacheOptions

Namespace
TcgDex.Caching
Assembly
TcgDex.CSharpSdk.dll

Controls response caching.

public class TcgDexCacheOptions

Inheritance

Inherited Members

Remarks

The API sends Cache-Control: no-cache, no-store, must-revalidate, which TCGdex has said was likely never set deliberately: caching is left to the application, and pricing updates once a day. This SDK's cache is an opt-in, application-level cache: it keeps entries for the freshness window and then revalidates them with If-None-Match, which the API answers with 304 and no body when nothing changed. Time-to-live therefore controls how long you are willing to serve data without asking, not how long before you pay for it again.

Not sealed: TcgDex.Caching.TcgDexCacheOptions.GetTimeToLive(System.Uri) is the extension point for a caller whose freshness policy differs from the path-based default.

Properties

CatalogTimeToLive

Freshness window for the enumeration endpoints.

public TimeSpan CatalogTimeToLive { get; set; }

Property Value

TimeSpan

Remarks

Much longer than TcgDex.Caching.TcgDexCacheOptions.DefaultTimeToLive because the set of rarities, types and trainer types changes when a new expansion ships, not minute to minute. These are also the endpoints an application calls repeatedly to build filters and pickers.

CoalesceConcurrentRequests

Whether to collapse concurrent identical requests into one.

public bool CoalesceConcurrentRequests { get; set; }

Property Value

bool

Remarks

On by default. Without it, a cold cache under concurrent load sends one request per caller for the same URL — the classic cache stampede. With it, the first caller fetches and the rest await that same result.

DefaultTimeToLive

Default freshness window for card, set and series responses.

public TimeSpan DefaultTimeToLive { get; set; }

Property Value

TimeSpan

MaxEntries

Maximum number of entries the default in-memory cache holds before evicting the least recently used.

public int MaxEntries { get; set; }

Property Value

int

Remarks

A bound matters here: a full set response is around 22 KB and there are hundreds of sets, so an unbounded cache in a long-running process is a slow memory leak.

PricingTimeToLive

Freshness window for responses that carry market pricing.

public TimeSpan PricingTimeToLive { get; set; }

Property Value

TimeSpan

Remarks

Short, because prices are the one part of a card that moves daily and serving a stale price is worse than serving a stale card name.

Methods

GetTimeToLive(Uri)

Chooses the freshness window for a request.

public virtual TimeSpan GetTimeToLive(Uri requestUri)

Parameters

requestUri Uri

The request being cached.

Returns

TimeSpan

How long the response may be served without revalidation.

Remarks

Override this to apply your own policy. The default classifies by path: enumeration endpoints get TcgDex.Caching.TcgDexCacheOptions.CatalogTimeToLive, single cards get TcgDex.Caching.TcgDexCacheOptions.PricingTimeToLive because they embed pricing, and everything else gets TcgDex.Caching.TcgDexCacheOptions.DefaultTimeToLive.