Class CachedResponse
- Namespace
- TcgDex.Caching
- Assembly
- TcgDex.CSharpSdk.dll
A cached HTTP response body together with the validator needed to refresh it.
public sealed class CachedResponseInheritance
Inherited Members
Remarks
The body is stored as bytes rather than as a deserialized model, so one cached entry serves every caller regardless of the type they deserialize into, and nothing mutable is ever shared between them.
A class with reference equality, not a record (DECISIONS #26). Record equality compares TcgDex.Caching.CachedResponse.Body by reference, so two entries with the same bytes compared equal or not depending on how the array was allocated. Comparing the bytes instead would cost a pass over every body and a hash that changes if the array is written to. No caller compares entries.
Properties
Body
The raw response body.
public required byte[] Body { get; init; }Property Value
- byte[]
ContentType
The Content-Type to replay, so cached responses parse identically.
public string? ContentType { get; init; }Property Value
ETag
The ETag the API returned, used to revalidate once the entry is no
longer fresh.
public string? ETag { get; init; }Property Value
Remarks
Without this a stale entry costs a full re-download. With it, an unchanged
resource costs a 304 and zero bytes of body.
StoredAt
When the entry was stored or last revalidated.
public required DateTimeOffset StoredAt { get; init; }Property Value
Methods
IsFresh(DateTimeOffset, TimeSpan)
Whether the entry is still within timeToLive of now.
public bool IsFresh(DateTimeOffset now, TimeSpan timeToLive)Parameters
nowDateTimeOffset-
The current time.
timeToLiveTimeSpan-
How long an entry may be served without revalidation.