CacheExtensions.GetOrCreate Method

Definition

Overloads

GetOrCreate<TItem>(IMemoryCache, Object, Func<ICacheEntry,TItem>)

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.

GetOrCreate<TItem>(IMemoryCache, Object, Func<ICacheEntry,TItem>, MemoryCacheEntryOptions)

GetOrCreate<TItem>(IMemoryCache, Object, Func<ICacheEntry,TItem>)

Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs

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:
generic <typename TItem>
[System::Runtime::CompilerServices::Extension]
 static TItem GetOrCreate(Microsoft::Extensions::Caching::Memory::IMemoryCache ^ cache, System::Object ^ key, Func<Microsoft::Extensions::Caching::Memory::ICacheEntry ^, TItem> ^ factory);
public static TItem GetOrCreate<TItem> (this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, Func<Microsoft.Extensions.Caching.Memory.ICacheEntry,TItem> factory);
public static TItem? GetOrCreate<TItem> (this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, Func<Microsoft.Extensions.Caching.Memory.ICacheEntry,TItem> factory);
static member GetOrCreate : Microsoft.Extensions.Caching.Memory.IMemoryCache * obj * Func<Microsoft.Extensions.Caching.Memory.ICacheEntry, 'Item> -> 'Item
<Extension()>
Public Function GetOrCreate(Of TItem) (cache As IMemoryCache, key As Object, factory As Func(Of ICacheEntry, TItem)) As TItem

Type Parameters

TItem

The type of the object to get.

Parameters

cache
IMemoryCache

The IMemoryCache instance this method extends.

key
Object

The key of the entry to look for or create.

factory
Func<ICacheEntry,TItem>

The factory that creates the value associated with this key if the key does not exist in the cache.

Returns

TItem

The value associated with this key.

Applies to

GetOrCreate<TItem>(IMemoryCache, Object, Func<ICacheEntry,TItem>, MemoryCacheEntryOptions)

Source:
MemoryCacheExtensions.cs
public:
generic <typename TItem>
[System::Runtime::CompilerServices::Extension]
 static TItem GetOrCreate(Microsoft::Extensions::Caching::Memory::IMemoryCache ^ cache, System::Object ^ key, Func<Microsoft::Extensions::Caching::Memory::ICacheEntry ^, TItem> ^ factory, Microsoft::Extensions::Caching::Memory::MemoryCacheEntryOptions ^ createOptions);
public static TItem? GetOrCreate<TItem> (this Microsoft.Extensions.Caching.Memory.IMemoryCache cache, object key, Func<Microsoft.Extensions.Caching.Memory.ICacheEntry,TItem> factory, Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions? createOptions);
static member GetOrCreate : Microsoft.Extensions.Caching.Memory.IMemoryCache * obj * Func<Microsoft.Extensions.Caching.Memory.ICacheEntry, 'Item> * Microsoft.Extensions.Caching.Memory.MemoryCacheEntryOptions -> 'Item
<Extension()>
Public Function GetOrCreate(Of TItem) (cache As IMemoryCache, key As Object, factory As Func(Of ICacheEntry, TItem), createOptions As MemoryCacheEntryOptions) As TItem

Type Parameters

TItem

Parameters

cache
IMemoryCache
key
Object
factory
Func<ICacheEntry,TItem>
createOptions
MemoryCacheEntryOptions

Returns

TItem

Applies to