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
timeout
TimeSpanThe 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
Methods
IsSupported(HttpMethod)
Determines whether the specified HTTP method is supported for caching.
protected virtual bool IsSupported(HttpMethod method)
Parameters
method
HttpMethodThe 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
HttpMethodThe HTTP method of the request.
uri
UriThe URI of the request.
body
objectThe request body.
Returns
- (HttpMethod, string, object)
A tuple that represents the cache key.
Exceptions
- ArgumentNullException
Thrown when
method
oruri
is null.