InMemoryRestApiClientCache
Represents an in-memory cache for REST API client responses.
Implements: IRestApiClientCache
Constructors
public InMemoryRestApiClientCache(TimeSpan timeout)
inMemoryRestApiClientCache = InMemoryRestApiClientCache(timeout)
Initializes a new instance of the InMemoryRestApiClientCache class with the specified timeout.
- timeout
- The duration after which a cached item expires.
public InMemoryRestApiClientCache(TimeSpan timeout, TimeProvider time)
inMemoryRestApiClientCache = InMemoryRestApiClientCache(timeout, time)
Initializes a new instance of the InMemoryRestApiClientCache class with the specified timeout.
- timeout
- How long a response outlives the last request for it.
- time
- The clock an item's age is measured on.
public InMemoryRestApiClientCache(TimeSpan timeout, TimeSpan maxAge, TimeProvider time)
inMemoryRestApiClientCache = InMemoryRestApiClientCache(timeout, maxAge, time)
Initializes a new instance of the InMemoryRestApiClientCache class.
- timeout
- How long a response outlives the last request for it.
- maxAge
- The oldest a response may be, however often it is requested.
- time
- The clock an item's age is measured on.
Properties
public TimeSpan MaxAge { get; }
value = inMemoryRestApiClientCache.MaxAge
Gets the oldest a response may be, however often it is requested.
public TimeSpan Timeout { get; }
value = inMemoryRestApiClientCache.Timeout
Gets how long a response outlives the last request for it.
Methods
protected virtual bool IsSupported(HttpMethod method)
result = inMemoryRestApiClientCache.IsSupported(method)
Determines whether the specified HTTP method is supported for caching.
- method
- The HTTP method of the request.
Returns: True if the method is supported; otherwise, false.
protected virtual ValueTuple<HttpMethod, string, object> ToKey(HttpMethod method, Uri uri, object body)
result = inMemoryRestApiClientCache.ToKey(method, uri, body)
Converts the provided HTTP method, URI, and body into a cache key.
- method
- The HTTP method of the request.
- uri
- The URI of the request.
- body
- The request body.
Returns: A tuple that represents the cache key.
Fields
protected readonly TtlCache<ValueTuple<HttpMethod, string, object>, object> Cache
value = inMemoryRestApiClientCache.Cache
The cache that stores the cached items.