RedisHttpCacheStore Class

Stores HTTP cache entries in Redis.

public sealed class RedisHttpCacheStore : IHttpCacheStore
Implements

Constructors

NameDescription
RedisHttpCacheStore(IConnectionMultiplexer, string)Initializes a new instance of the RedisHttpCacheStore class with no limit.
RedisHttpCacheStore(IConnectionMultiplexer, string, HttpCacheStoreLimits?)Initializes a new instance of the RedisHttpCacheStore class that evicts the least recently used entries to stay within limits.

RedisHttpCacheStore overloads

RedisHttpCacheStore(IConnectionMultiplexer, string)

RedisHttpCacheStore.cs

Initializes a new instance of the RedisHttpCacheStore class with no limit.

public RedisHttpCacheStore(IConnectionMultiplexer connectionMultiplexer, string keyPrefix = "Meziantou:HttpCache")
Parameters
connectionMultiplexer IConnectionMultiplexer
The Redis connection multiplexer.
keyPrefix string
The key prefix used to isolate cache entries in Redis.

RedisHttpCacheStore(IConnectionMultiplexer, string, HttpCacheStoreLimits?)

RedisHttpCacheStore.cs

Initializes a new instance of the RedisHttpCacheStore class that evicts the least recently used entries to stay within limits.

public RedisHttpCacheStore(IConnectionMultiplexer connectionMultiplexer, string keyPrefix, HttpCacheStoreLimits? limits)
Parameters
connectionMultiplexer IConnectionMultiplexer
The Redis connection multiplexer.
keyPrefix string
The key prefix used to isolate cache entries in Redis.
limits HttpCacheStoreLimits?
The bounds of the store, or null for no limit. The values are read once, by the constructor.
Remarks

A bounded store updates its keys with Lua scripts. With Redis Cluster, the keys of the store must be in the same slot: use a key prefix with a hash tag, such as {MyApp}:HttpCache.

Methods

NameDescription
GetEntriesAsync(string, CancellationToken)Gets all entries associated with a primary cache key.
PruneObsoleteEntriesAsync(DateTimeOffset, CancellationToken)Removes expired entries that cannot be reused when stale.
PruneObsoleteEntriesAsync(CancellationToken)Removes expired entries that cannot be reused when stale.
RemoveEntriesAsync(string, CancellationToken)Removes all entries associated with a primary cache key.
SetEntryAsync(string, HttpCachePersistenceEntry, CancellationToken)Adds or replaces a cache entry for a primary key.

GetEntriesAsync(string, CancellationToken)

RedisHttpCacheStore.cs

Gets all entries associated with a primary cache key.

net10.0

public ValueTask<IReadOnlyCollection<HttpCachePersistenceEntry>> GetEntriesAsync(string primaryKey, CancellationToken cancellationToken)

net11.0

public ValueTask<IReadOnlyCollection<HttpCachePersistenceEntry>> GetEntriesAsync(string primaryKey, CancellationToken cancellationToken)

Parameters

primaryKey string
The primary cache key.
cancellationToken CancellationToken
The cancellation token.

Returns

ValueTask<IReadOnlyCollection<HttpCachePersistenceEntry>>

PruneObsoleteEntriesAsync overloads

PruneObsoleteEntriesAsync(DateTimeOffset, CancellationToken)

RedisHttpCacheStore.cs

Removes expired entries that cannot be reused when stale.

net10.0

public ValueTask PruneObsoleteEntriesAsync(DateTimeOffset now, CancellationToken cancellationToken = default)

net11.0

public ValueTask PruneObsoleteEntriesAsync(DateTimeOffset now, CancellationToken cancellationToken = default)
Parameters
now DateTimeOffset
The current time used to evaluate expiration.
cancellationToken CancellationToken
The cancellation token.
Returns

ValueTask

PruneObsoleteEntriesAsync(CancellationToken)

RedisHttpCacheStore.cs

Removes expired entries that cannot be reused when stale.

public ValueTask PruneObsoleteEntriesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken CancellationToken
The cancellation token.
Returns

ValueTask

RemoveEntriesAsync(string, CancellationToken)

RedisHttpCacheStore.cs

Removes all entries associated with a primary cache key.

net10.0

public ValueTask RemoveEntriesAsync(string primaryKey, CancellationToken cancellationToken)

net11.0

public ValueTask RemoveEntriesAsync(string primaryKey, CancellationToken cancellationToken)

Parameters

primaryKey string
The primary cache key.
cancellationToken CancellationToken
The cancellation token.

Returns

ValueTask

SetEntryAsync(string, HttpCachePersistenceEntry, CancellationToken)

RedisHttpCacheStore.cs

Adds or replaces a cache entry for a primary key.

net10.0

public ValueTask SetEntryAsync(string primaryKey, HttpCachePersistenceEntry entry, CancellationToken cancellationToken)

net11.0

public ValueTask SetEntryAsync(string primaryKey, HttpCachePersistenceEntry entry, CancellationToken cancellationToken)

Parameters

primaryKey string
The primary cache key.
entry HttpCachePersistenceEntry
The entry to store.
cancellationToken CancellationToken
The cancellation token.

Returns

ValueTask