constructorMemoryCacheProvider
public MemoryCacheProvider(IOptions<MemoryCacheOptions>? options, TimeProvider? timeProvider = null)
Initializes a new instance of the `MemoryCacheProvider` class with Microsoft DI options.
- options: IOptions<MemoryCacheOptions>?
- Configuration options wrapped in `IOptions<MemoryCacheOptions>`.
- timeProvider: TimeProvider?
- Optional time provider for unit testing expiration.
constructorMemoryCacheProvider
public MemoryCacheProvider(MemoryCacheOptions? options, TimeProvider? timeProvider = null)
Initializes a new instance of the `MemoryCacheProvider` class with explicit configuration options.
- options: MemoryCacheOptions?
- Configuration options.
- timeProvider: TimeProvider?
- Optional time provider for unit testing expiration.
constructorMemoryCacheProvider
public MemoryCacheProvider(TimeProvider? timeProvider = null)
Initializes a new instance of the `MemoryCacheProvider` class with optional time provider.
- timeProvider: TimeProvider?
- Optional time provider for unit testing expiration.
methodDispose
public void Dispose()
Inherits documentation from base type or interface.
methodExistsAsync
public Task<Result<bool>> ExistsAsync(string key, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- key: string
- cancellationToken: CancellationToken
methodExpireAsync
public Task<Result<bool>> ExpireAsync(string key, TimeSpan timeToLive, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- key: string
- timeToLive: TimeSpan
- cancellationToken: CancellationToken
methodGetAsync<T>
public Task<Result<T?>> GetAsync<T>(string key, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- key: string
- cancellationToken: CancellationToken
methodGetManyAsync<T>
public Task<Result<IReadOnlyDictionary<string, T>>> GetManyAsync<T>(IEnumerable<string> keys, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- keys: IEnumerable<string>
- cancellationToken: CancellationToken
methodGetOrCreateAsync<T>
public async Task<Result<T>> GetOrCreateAsync<T>(string key, Func<CancellationToken, Task<T>> factory, CacheEntryOptions? options = null, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- key: string
- factory: Func<CancellationToken, Task<T>>
- options: CacheEntryOptions?
- cancellationToken: CancellationToken
methodRefreshAsync
public Task<Result<bool>> RefreshAsync(string key, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- key: string
- cancellationToken: CancellationToken
methodRemoveAsync
public Task<Result<bool>> RemoveAsync(string key, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- key: string
- cancellationToken: CancellationToken
methodRemoveByPrefixAsync
public Task<Result<bool>> RemoveByPrefixAsync(string prefix, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- prefix: string
- cancellationToken: CancellationToken
methodRemoveByTagAsync
public Task<Result<bool>> RemoveByTagAsync(string tag, CancellationToken cancellationToken = default)
Evicts all cache entries associated with the specified tag.
- tag: string
- The tag whose associated entries will be removed.
- cancellationToken: CancellationToken
- Cancellation token.
Returns: A `Result<T>` indicating whether the eviction succeeded.
methodRemoveByTagsAsync
public async Task<Result<bool>> RemoveByTagsAsync(IEnumerable<string> tags, CancellationToken cancellationToken = default)
Evicts all cache entries associated with any of the specified tags.
- tags: IEnumerable<string>
- The collection of tags whose associated entries will be removed.
- cancellationToken: CancellationToken
- Cancellation token.
Returns: A `Result<T>` indicating whether the eviction succeeded.
methodRemoveExpiredEntries
public int RemoveExpiredEntries()
Scans the internal cache storage and actively evicts all entries whose expiration duration has elapsed and are no longer eligible for stale fallback. Cleans up associated tag indices.
Returns: The number of expired entries successfully evicted from memory.
methodRemoveManyAsync
public Task<Result<long>> RemoveManyAsync(IEnumerable<string> keys, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- keys: IEnumerable<string>
- cancellationToken: CancellationToken
methodSetAsync<T>
public Task<Result<bool>> SetAsync<T>(string key, T value, CacheEntryOptions? options = null, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- key: string
- value: T
- options: CacheEntryOptions?
- cancellationToken: CancellationToken
methodSetManyAsync<T>
public async Task<Result<bool>> SetManyAsync<T>(IEnumerable<KeyValuePair<string, T>> items, CacheEntryOptions? options = null, CancellationToken cancellationToken = default)
Inherits documentation from base type or interface.
- items: IEnumerable<KeyValuePair<string, T>>
- options: CacheEntryOptions?
- cancellationToken: CancellationToken
methodSetWithTagsAsync<T>
public Task<Result<bool>> SetWithTagsAsync<T>(string key, T value, IEnumerable<string> tags, CacheEntryOptions? options = null, CancellationToken cancellationToken = default)
Sets a value in the cache associated with one or more tags.
- key: string
- The unique cache key.
- value: T
- The value to cache.
- tags: IEnumerable<string>
- The collection of tags to associate with this cache entry.
- options: CacheEntryOptions?
- Optional expiration and eviction options.
- cancellationToken: CancellationToken
- Cancellation token.
Returns: A `Result<T>` indicating whether the operation succeeded.