Microsoft.Extensions.Caching.Memory.CacheExtensions
Provides extensions methods for IMemoryCache operations.
Gets the value associated with this key if present.
Gets the value associated with this key if present.
public static TItem GetOrCreate<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, TItem> factory)
Gets the value associated with this key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.
public static TItem GetOrCreate<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, TItem> factory, MemoryCacheEntryOptions createOptions)
Gets the value associated with this key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.
public static Task<TItem> GetOrCreateAsync<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, Task<TItem>> factory)
Asynchronously gets the value associated with this key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.
public static Task<TItem> GetOrCreateAsync<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, Task<TItem>> factory, MemoryCacheEntryOptions createOptions)
Asynchronously gets the value associated with this key if it exists, or generates a new entry using the provided key and a value from the given factory if the key is not found.
Associate a value with a key in the IMemoryCache.
public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, DateTimeOffset absoluteExpiration)
Sets a cache entry with the given key and value that will expire in the given duration.
public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, TimeSpan absoluteExpirationRelativeToNow)
Sets a cache entry with the given key and value that will expire in the given duration from now.
public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, IChangeToken expirationToken)
Sets a cache entry with the given key and value that will expire when IChangeToken expires.
public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, MemoryCacheEntryOptions options)
Sets a cache entry with the given key and value and apply the values of an existing MemoryCacheEntryOptions to the created entry.
Tries to get the value associated with the given key.