InMemoryHttpCacheStore Class

Stores HTTP cache entries in-memory and can persist them to a JSON file.

public sealed class InMemoryHttpCacheStore : IHttpCacheStore
Implements

Constructors

NameDescription
InMemoryHttpCacheStore()

InMemoryHttpCacheStore()

InMemoryHttpCacheStore.cs
public InMemoryHttpCacheStore()

No documentation is available.

Methods

NameDescription
GetEntriesAsync(string, CancellationToken)Gets all entries associated with a primary cache key.
LoadFromFileAsync(string, CancellationToken)Loads cache entries from a JSON file and replaces current in-memory entries.
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.
SaveToFileAsync(string, CancellationToken)Saves all in-memory cache entries to a JSON file.
SetEntryAsync(string, HttpCachePersistenceEntry, CancellationToken)Adds or replaces a cache entry for a primary key.

GetEntriesAsync(string, CancellationToken)

InMemoryHttpCacheStore.cs

Gets all entries associated with a primary cache key.

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>>

LoadFromFileAsync(string, CancellationToken)

InMemoryHttpCacheStore.cs

Loads cache entries from a JSON file and replaces current in-memory entries.

net10.0

public ValueTask LoadFromFileAsync(string filePath, CancellationToken cancellationToken = default)

net11.0

public ValueTask LoadFromFileAsync(string filePath, CancellationToken cancellationToken = default)

Parameters

filePath string
The path of the file to read.
cancellationToken CancellationToken
The cancellation token.

Returns

ValueTask

PruneObsoleteEntriesAsync overloads

PruneObsoleteEntriesAsync(DateTimeOffset, CancellationToken)

InMemoryHttpCacheStore.cs

Removes expired entries that cannot be reused when stale.

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)

InMemoryHttpCacheStore.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)

InMemoryHttpCacheStore.cs

Removes all entries associated with a primary cache key.

public ValueTask RemoveEntriesAsync(string primaryKey, CancellationToken cancellationToken)

Parameters

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

Returns

ValueTask

SaveToFileAsync(string, CancellationToken)

InMemoryHttpCacheStore.cs

Saves all in-memory cache entries to a JSON file.

net10.0

public ValueTask SaveToFileAsync(string filePath, CancellationToken cancellationToken = default)

net11.0

public ValueTask SaveToFileAsync(string filePath, CancellationToken cancellationToken = default)

Parameters

filePath string
The path of the file to write.
cancellationToken CancellationToken
The cancellation token.

Returns

ValueTask

SetEntryAsync(string, HttpCachePersistenceEntry, CancellationToken)

InMemoryHttpCacheStore.cs

Adds or replaces a cache entry for a primary key.

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