CacheExtensions.GetOrCreateAsync 方法

定义

重载

GetOrCreateAsync<TItem>(IMemoryCache, Object, Func<ICacheEntry,Task<TItem>>)

如果存在,则异步获取与此键关联的值,或者在找不到密钥时使用提供的键和给定工厂中的值生成新条目。

GetOrCreateAsync<TItem>(IMemoryCache, Object, Func<ICacheEntry,Task<TItem>>, MemoryCacheEntryOptions)

如果存在,则异步获取与此键关联的值,或者在找不到密钥时使用提供的键和给定工厂中的值生成新条目。

GetOrCreateAsync<TItem>(IMemoryCache, Object, Func<ICacheEntry,Task<TItem>>)

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

如果存在,则异步获取与此键关联的值,或者在找不到密钥时使用提供的键和给定工厂中的值生成新条目。

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

类型参数

TItem

要获取的对象的类型。

参数

cache
IMemoryCache

此方法扩展 IMemoryCache 实例。

key
Object

要查找或创建的条目的键。

factory
Func<ICacheEntry,Task<TItem>>

如果缓存中不存在密钥,则创建与此键关联的值的工厂任务。

返回

Task<TItem>

表示异步操作的任务对象。

适用于

GetOrCreateAsync<TItem>(IMemoryCache, Object, Func<ICacheEntry,Task<TItem>>, MemoryCacheEntryOptions)

Source:
MemoryCacheExtensions.cs
Source:
MemoryCacheExtensions.cs

如果存在,则异步获取与此键关联的值,或者在找不到密钥时使用提供的键和给定工厂中的值生成新条目。

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

类型参数

TItem

要获取的对象的类型。

参数

cache
IMemoryCache

此方法扩展 IMemoryCache 实例。

key
Object

要查找或创建的条目的键。

factory
Func<ICacheEntry,Task<TItem>>

如果缓存中不存在密钥,则创建与此键关联的值的工厂任务。

createOptions
MemoryCacheEntryOptions

如果缓存中不存在密钥,则应用于 ICacheEntry 的选项。

返回

Task<TItem>

表示异步操作的任务对象。

适用于