HttpCachingOptions Class

Options for configuring HTTP caching behavior.

public sealed class HttpCachingOptions

Constructors

NameDescription
HttpCachingOptions()

HttpCachingOptions()

HttpCachingOptions.cs
public HttpCachingOptions()

No documentation is available.

Properties

NameDescription
CoalesceRequestsGets or sets a value indicating whether concurrent requests for the same URL share a single request to the server.
IsSharedCacheGets or sets a value indicating whether the cache follows the rules of a shared cache (RFC 9111), such as a proxy serving several users.
MaximumResponseSizeGets or sets the maximum size in bytes that a response can be to be cached. Responses larger than this value will not be cached. Default is 5 MB (5,242,880 bytes). Set to null to disable size checking.
OnStoreErrorGets or sets a callback invoked when the cache store fails. A store failure never fails the request: the lookup is treated as a miss and the write is skipped, so a degraded store degrades to no caching rather than to a broken HttpClient. This callback is the only way to observe that, so set it if you need the failures to be visible. Default is null (store failures are silently ignored).
ShouldCacheResponseGets or sets a predicate that determines whether a response should be cached. When the predicate returns true, normal caching logic applies. When the predicate returns false, the response is not cached. Default is null (all responses that meet caching requirements are cached).
TimeProviderGets or sets the time provider used for time-based cache operations.

CoalesceRequests

HttpCachingOptions.cs

Gets or sets a value indicating whether concurrent requests for the same URL share a single request to the server.

public bool CoalesceRequests { get; set; }

Property value

bool

Remarks

When a request must go to the server (no stored response, or a stale one to revalidate), the concurrent requests with the same method and URL wait for it to complete, then look up the cache again. The ones the stored response can answer are served from the cache; the others, for instance because the response varies on a header they send differently, or because it could not be stored, go to the server themselves. Requests with a Range header do not take part in coalescing. Default is false.

Gets or sets a value indicating whether the cache follows the rules of a shared cache (RFC 9111), such as a proxy serving several users.

public bool IsSharedCache { get; set; }

Property value

bool

Remarks

A shared cache does not store the responses marked private, does not store the responses to requests with an Authorization header unless the response allows it (public, s-maxage or must-revalidate), uses s-maxage over max-age and Expires, and honors proxy-revalidate. Default is false (a private cache that belongs to a single user).

MaximumResponseSize

HttpCachingOptions.cs

Gets or sets the maximum size in bytes that a response can be to be cached. Responses larger than this value will not be cached. Default is 5 MB (5,242,880 bytes). Set to null to disable size checking.

public long? MaximumResponseSize { get; set; }

Property value

long?

Gets or sets a callback invoked when the cache store fails. A store failure never fails the request: the lookup is treated as a miss and the write is skipped, so a degraded store degrades to no caching rather than to a broken HttpClient. This callback is the only way to observe that, so set it if you need the failures to be visible. Default is null (store failures are silently ignored).

public Action<Exception>? OnStoreError { get; set; }

Property value

Action<Exception>?

ShouldCacheResponse

HttpCachingOptions.cs

Gets or sets a predicate that determines whether a response should be cached. When the predicate returns true, normal caching logic applies. When the predicate returns false, the response is not cached. Default is null (all responses that meet caching requirements are cached).

public Func<HttpResponseMessage, bool>? ShouldCacheResponse { get; set; }

Gets or sets the time provider used for time-based cache operations.

public TimeProvider TimeProvider { get; set; }

Property value

TimeProvider