HttpCachePersistenceEntry Class

Represents a persisted HTTP cache entry.

public sealed class HttpCachePersistenceEntry

Remarks

This type is part of IHttpCacheStore public contract. It allows custom providers to persist cache metadata without exposing internal cache implementation details.

Constructors

NameDescription
HttpCachePersistenceEntry()

HttpCachePersistenceEntry()

public HttpCachePersistenceEntry()

No documentation is available.

Properties

NameDescription
AgeValueGets or sets the age value.
ETagGets or sets the ETag validator.
ExpiresGets or sets the Expires header value.
ImmutableGets or sets a value indicating whether immutable is set.
IsUnusableWhenStaleGets a value indicating whether the entry becomes unusable as soon as it is stale.
LastModifiedGets or sets the Last-Modified validator.
MaxAgeGets or sets the max-age directive value.
MustRevalidateGets or sets a value indicating whether must-revalidate is set.
NoTransformGets or sets a value indicating whether no-transform is set.
NoVarySearchGets or sets the canonical No-Vary-Search value of the response, or null when the response does not declare one.
NormalizedQueryGets or sets the query the response was stored for, canonicalized with HttpCachePersistenceEntry.NoVarySearch.
PrivateGets or sets a value indicating whether private is set.
ProxyRevalidateGets or sets a value indicating whether proxy-revalidate is set.
PublicGets or sets a value indicating whether public is set.
RequestTimeGets or sets the request time.
ResponseDateGets or sets the response date.
ResponseNoCacheGets or sets a value indicating whether no-cache is set.
ResponseTimeGets or sets the response time.
SecondaryKeyHeadersGets or sets the normalized vary-based secondary key headers.
SecondaryKeyMatchNoneGets or sets a value indicating whether this entry should never match requests. Corresponds to the Vary: * behavior.
SerializedResponseGets or sets the serialized HTTP response payload.
SharedMaxAgeGets or sets the s-maxage directive value.
StaleIfErrorGets or sets the stale-if-error value.

Gets or sets the age value.

public TimeSpan AgeValue { get; set; }

Property value

TimeSpan

Gets or sets the ETag validator.

public string? ETag { get; set; }

Property value

string?

Gets or sets the Expires header value.

public DateTimeOffset? Expires { get; set; }

Property value

DateTimeOffset?

Gets or sets a value indicating whether immutable is set.

public bool Immutable { get; set; }

Property value

bool

IsUnusableWhenStale

HttpCachePersistenceEntry.cs

Gets a value indicating whether the entry becomes unusable as soon as it is stale.

public bool IsUnusableWhenStale { get; }

Property value

bool

Remarks

Two things keep an entry useful past its freshness lifetime: a validator, which lets it be revalidated with a conditional request, and stale-if-error (RFC 5861), which lets it be served as-is while the origin is failing. An entry with neither can only ever be discarded once it is stale, so a store is free to reclaim it.

must-revalidate, proxy-revalidate and no-cache are deliberately not consulted. They say when a stored response must be revalidated before reuse, not whether it can be reused at all, so requiring one of them here left an ordinary max-age entry unreclaimable forever.

Gets or sets the Last-Modified validator.

public DateTimeOffset? LastModified { get; set; }

Property value

DateTimeOffset?

Gets or sets the max-age directive value.

public TimeSpan? MaxAge { get; set; }

Property value

TimeSpan?

Gets or sets a value indicating whether must-revalidate is set.

public bool MustRevalidate { get; set; }

Property value

bool

Gets or sets a value indicating whether no-transform is set.

public bool NoTransform { get; set; }

Property value

bool

Gets or sets the canonical No-Vary-Search value of the response, or null when the response does not declare one.

public string? NoVarySearch { get; set; }

Property value

string?

Gets or sets the query the response was stored for, canonicalized with HttpCachePersistenceEntry.NoVarySearch.

public string? NormalizedQuery { get; set; }

Property value

string?

Remarks

Only set together with HttpCachePersistenceEntry.NoVarySearch: those entries are stored under a primary key that leaves the query out, so the query belongs to their secondary key.

Gets or sets a value indicating whether private is set.

public bool Private { get; set; }

Property value

bool

Gets or sets a value indicating whether proxy-revalidate is set.

public bool ProxyRevalidate { get; set; }

Property value

bool

Gets or sets a value indicating whether public is set.

public bool Public { get; set; }

Property value

bool

Gets or sets the request time.

public DateTimeOffset RequestTime { get; set; }

Property value

DateTimeOffset

Gets or sets the response date.

public DateTimeOffset ResponseDate { get; set; }

Property value

DateTimeOffset

Gets or sets a value indicating whether no-cache is set.

public bool ResponseNoCache { get; set; }

Property value

bool

Gets or sets the response time.

public DateTimeOffset ResponseTime { get; set; }

Property value

DateTimeOffset

SecondaryKeyHeaders

HttpCachePersistenceEntry.cs

Gets or sets the normalized vary-based secondary key headers.

public Dictionary<string, string>? SecondaryKeyHeaders { get; set; }

SecondaryKeyMatchNone

HttpCachePersistenceEntry.cs

Gets or sets a value indicating whether this entry should never match requests. Corresponds to the Vary: * behavior.

public bool SecondaryKeyMatchNone { get; set; }

Property value

bool

Gets or sets the serialized HTTP response payload.

public ReadOnlyMemory<byte> SerializedResponse { get; set; }

Property value

ReadOnlyMemory<byte>

Gets or sets the s-maxage directive value.

public TimeSpan? SharedMaxAge { get; set; }

Property value

TimeSpan?

Gets or sets the stale-if-error value.

public TimeSpan? StaleIfError { get; set; }

Property value

TimeSpan?

Methods

NameDescription
Clone()Creates a deep clone of the current instance.
ComputeSecondaryKeyHash()Computes a stable hash of the secondary key, suitable for use as a storage key.
GetCurrentAge(DateTimeOffset)Computes the age of the entry at the specified time, as defined by RFC 7234 Section 4.2.3.
GetFreshnessLifetime()Computes the freshness lifetime of the entry, as defined by RFC 7234 Section 4.2.1.
GetStaleTime()Gets the time at which the entry becomes stale.
HasSameSecondaryKey(HttpCachePersistenceEntry, HttpCachePersistenceEntry)Indicates whether two entries share the same secondary key.
IsObsolete(DateTimeOffset)Indicates whether the entry is stale and cannot be reused, and can therefore be removed by a store.

Creates a deep clone of the current instance.

ComputeSecondaryKeyHash()

HttpCachePersistenceEntry.cs

Computes a stable hash of the secondary key, suitable for use as a storage key.

public string ComputeSecondaryKeyHash()

Returns

string

Remarks

Two entries that HttpCachePersistenceEntry.HasSameSecondaryKey considers the same have the same hash, whatever the comparer of their HttpCachePersistenceEntry.SecondaryKeyHeaders.

GetCurrentAge(DateTimeOffset)

HttpCachePersistenceEntry.cs

Computes the age of the entry at the specified time, as defined by RFC 7234 Section 4.2.3.

public TimeSpan GetCurrentAge(DateTimeOffset now)

Parameters

now DateTimeOffset
The time at which the age is evaluated.

Returns

TimeSpan

GetFreshnessLifetime()

HttpCachePersistenceEntry.cs

Computes the freshness lifetime of the entry, as defined by RFC 7234 Section 4.2.1.

public TimeSpan GetFreshnessLifetime()

Returns

TimeSpan

Gets the time at which the entry becomes stale.

public DateTimeOffset GetStaleTime()

Returns

DateTimeOffset

Remarks

The result is clamped to the range of DateTimeOffset. Stores can index this value to remove obsolete entries without deserializing them.

HasSameSecondaryKey(HttpCachePersistenceEntry, HttpCachePersistenceEntry)

HttpCachePersistenceEntry.cs

Indicates whether two entries share the same secondary key.

public static bool HasSameSecondaryKey(HttpCachePersistenceEntry left, HttpCachePersistenceEntry right)

Parameters

left HttpCachePersistenceEntry
right HttpCachePersistenceEntry

Returns

bool

Remarks

Header names are compared case-insensitively (RFC 9110 Section 5.1) whatever the comparer of the HttpCachePersistenceEntry.SecondaryKeyHeaders: a store that deserializes an entry gets a case-sensitive dictionary.

IsObsolete(DateTimeOffset)

HttpCachePersistenceEntry.cs

Indicates whether the entry is stale and cannot be reused, and can therefore be removed by a store.

public bool IsObsolete(DateTimeOffset now)

Parameters

now DateTimeOffset
The time at which staleness is evaluated.

Returns

bool