Table of Contents

Class ResponseCache

Namespace
TypedRest.Http
Assembly
TypedRest.dll

Captures the content of an HttpResponseMessage for caching.

public sealed class ResponseCache
Inheritance
object
ResponseCache

Methods

From(HttpResponseMessage)

Creates a ResponseCache from a response if it is eligible for caching.

public static ResponseCache? From(HttpResponseMessage response)

Parameters

response HttpResponseMessage

Returns

ResponseCache

The ResponseCache; null if the response is not eligible for caching.

FromPut(HttpResponseMessage, byte[], MediaTypeHeaderValue?)

Creates a ResponseCache from the response to a PUT request if the server sent an ETag.

public static ResponseCache? FromPut(HttpResponseMessage response, byte[] requestContent, MediaTypeHeaderValue? requestContentType)

Parameters

response HttpResponseMessage

The response to the PUT request.

requestContent byte[]

The body of the PUT request.

requestContentType MediaTypeHeaderValue

The media type of requestContent.

Returns

ResponseCache

The ResponseCache; null if the response is not eligible for caching.

GetContent()

Returns a new HttpContent backed by the cached bytes.

public HttpContent GetContent()

Returns

HttpContent

Remarks

Each call produces an independent copy so the body can be consumed multiple times.

SetIfModifiedHeaders(HttpRequestHeaders)

Sets request headers asserting that the resource has been modified since it was cached.

public void SetIfModifiedHeaders(HttpRequestHeaders headers)

Parameters

headers HttpRequestHeaders

Remarks

Suitable for GET/HEAD requests that should bypass the cache.

SetIfUnmodifiedHeaders(HttpRequestHeaders)

Sets request headers asserting that the resource has not been modified since it was cached.

public void SetIfUnmodifiedHeaders(HttpRequestHeaders headers)

Parameters

headers HttpRequestHeaders

Remarks

Suitable for PUT/DELETE requests to prevent lost updates.