Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class Microsoft.​Extensions.​Caching.​Memory.​CacheExtensions

Assembly: Microsoft.Extensions.Caching.Abstractions

Inheritance: object → CacheExtensions

Provides extensions methods for <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> operations.

Methods

public static object
Get​(IMemoryCache cache, object key)
Gets the value associated with this key if present.
Returns The value associated with this key, or <c>null</c> if the key is not present.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the value to get.
public static System.​Threading.​Tasks.​Task<​TItem>
GetOrCreateAsync​(IMemoryCache cache, object key, System.​Func<​ICacheEntry, System.​Threading.​Tasks.​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.
Returns The task object representing the asynchronous operation.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the entry to look for or create.
factory The factory task that creates the value associated with this key if the key does not exist in the cache.
public static System.​Threading.​Tasks.​Task<​TItem>
GetOrCreateAsync​(IMemoryCache cache, object key, System.​Func<​ICacheEntry, System.​Threading.​Tasks.​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.
Returns The task object representing the asynchronous operation.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the entry to look for or create.
factory The factory task that creates the value associated with this key if the key does not exist in the cache.
createOptions The options to be applied to the <see cref="T:Microsoft.Extensions.Caching.Memory.ICacheEntry" /> if the key does not exist in the cache.
public static TItem
GetOrCreate​(IMemoryCache cache, object key, System.​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.
Returns The value associated with this key.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the entry to look for or create.
factory The factory that creates the value associated with this key if the key does not exist in the cache.
public static TItem
GetOrCreate​(IMemoryCache cache, object key, System.​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.
Returns The value associated with this key.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the entry to look for or create.
factory The factory that creates the value associated with this key if the key does not exist in the cache.
createOptions The options to be applied to the <see cref="T:Microsoft.Extensions.Caching.Memory.ICacheEntry" /> if the key does not exist in the cache.
public static TItem
Get​(IMemoryCache cache, object key)
Gets the value associated with this key if present.
Returns The value associated with this key, or <c>default(TItem)</c> if the key is not present.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the value to get.
public static TItem
Set​(IMemoryCache cache, object key, TItem value)
Associate a value with a key in the <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> .
Returns The value that was set.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the entry to set.
value The value to associate with the key.
public static TItem
Set​(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 <see cref="T:Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions" /> to the created entry.
Returns The value that was set.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the entry to set.
value The value to associate with the key.
options The existing <see cref="T:Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions" /> instance to apply to the new entry.
public static TItem
Set​(IMemoryCache cache, object key, TItem value, Primitives.​IChangeToken expirationToken)
Sets a cache entry with the given key and value that will expire when <see cref="T:Microsoft.Extensions.Primitives.IChangeToken" /> expires.
Returns The value that was set.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the entry to set.
value The value to associate with the key.
expirationToken The <see cref="T:Microsoft.Extensions.Primitives.IChangeToken" /> that causes the cache entry to expire.
public static TItem
Set​(IMemoryCache cache, object key, TItem value, System.​DateTimeOffset absoluteExpiration)
Sets a cache entry with the given key and value that will expire in the given duration.
Returns The value that was set.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the entry to set.
value The value to associate with the key.
absoluteExpiration The point in time at which the cache entry will expire.
public static TItem
Set​(IMemoryCache cache, object key, TItem value, System.​TimeSpan absoluteExpirationRelativeToNow)
Sets a cache entry with the given key and value that will expire in the given duration from now.
Returns The value that was set.
cache The <see cref="T:Microsoft.Extensions.Caching.Memory.IMemoryCache" /> instance this method extends.
key The key of the entry to set.
value The value to associate with the key.
absoluteExpirationRelativeToNow The duration from now after which the cache entry will expire.
public static bool
TryGetValue​(IMemoryCache cache, object key, TItem&? value)
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object