<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="10.0.12" />

Microsoft.Extensions.Caching.Memory.CacheExtensions

public static class CacheExtensions
Provides extensions methods for IMemoryCache operations.
public static object Get(this IMemoryCache cache, object key)

Gets the value associated with this key if present.

public static TItem Get<TItem>(this IMemoryCache cache, object key)

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.

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value)

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.

public static bool TryGetValue<TItem>(this IMemoryCache cache, object key, out TItem value)

Tries to get the value associated with the given key.