Class TcgDexCacheOptions
- Namespace
- TcgDex.Caching
- Assembly
- TcgDex.CSharpSdk.dll
Controls response caching.
public class TcgDexCacheOptionsInheritance
Inherited Members
Remarks
The API sends Cache-Control: no-store, so nothing caches by default and
enabling this is an explicit choice about your own data freshness. What makes
it safe is that the API also honours If-None-Match: once an entry is no
longer fresh it is revalidated rather than re-fetched, so a resource
that has not changed costs a 304 and zero bytes of body.
Time-to-live therefore controls how long you are willing to serve data without asking, not how long before you pay for it again.
Properties
CatalogTimeToLive
Freshness window for the enumeration endpoints.
public TimeSpan CatalogTimeToLive { get; set; }Property Value
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
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
MaxEntries
Maximum number of entries the default in-memory cache holds before evicting the least recently used.
public int MaxEntries { get; set; }Property Value
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
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
requestUriUri-
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.