Class InMemoryRestApiClientCache
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
timeoutTimeSpanThe duration after which a cached item expires.
Exceptions
- ArgumentOutOfRangeException
Thrown when
timeoutis less than or equal to zero.
Fields
Cache
The cache that stores the cached items.
protected readonly SynchronizedDictionary<(HttpMethod method, string uri, object body), (object value, DateTime till)> Cache
Field Value
Properties
Timeout
Gets the timeout duration for cached items.
public TimeSpan Timeout { get; }
Property Value
Methods
IsSupported(HttpMethod)
Determines whether the specified HTTP method is supported for caching.
protected virtual bool IsSupported(HttpMethod method)
Parameters
methodHttpMethodThe 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
methodHttpMethodThe HTTP method of the request.
uriUriThe URI of the request.
bodyobjectThe request body.
Returns
- (HttpMethod, string, object)
A tuple that represents the cache key.
Exceptions
- ArgumentNullException
Thrown when
methodoruriis null.