Table of Contents

Class InMemoryRestApiClientCache

Namespace
Ecng.Net
Assembly
Ecng.Net.Clients.dll

Represents an in-memory cache for REST API client responses.

public class InMemoryRestApiClientCache : IRestApiClientCache
Inheritance
InMemoryRestApiClientCache
Implements
Inherited Members
Extension Methods

Constructors

InMemoryRestApiClientCache(TimeSpan)

Initializes a new instance of the InMemoryRestApiClientCache class with the specified timeout.

public InMemoryRestApiClientCache(TimeSpan timeout)

Parameters

timeout TimeSpan

The duration after which a cached item expires.

Exceptions

ArgumentOutOfRangeException

Thrown when timeout is less than or equal to zero.

Fields

Cache

The cache that stores the cached items.

protected readonly SynchronizedDictionary<(HttpMethod, string, object), (object, DateTime)> Cache

Field Value

SynchronizedDictionary<(HttpMethod, string, object), (object, DateTime)>

Properties

Timeout

Gets the timeout duration for cached items.

public TimeSpan Timeout { get; }

Property Value

TimeSpan

Methods

IsSupported(HttpMethod)

Determines whether the specified HTTP method is supported for caching.

protected virtual bool IsSupported(HttpMethod method)

Parameters

method HttpMethod

The HTTP method of the request.

Returns

bool

True if the method is supported; otherwise, false.

ToKey(HttpMethod, Uri, object)

Converts the provided HTTP method, URI, and body into a cache key.

protected virtual (HttpMethod, string, object) ToKey(HttpMethod method, Uri uri, object body)

Parameters

method HttpMethod

The HTTP method of the request.

uri Uri

The URI of the request.

body object

The request body.

Returns

(HttpMethod, string, object)

A tuple that represents the cache key.

Exceptions

ArgumentNullException

Thrown when method or uri is null.