CacheExtensions.GetOrCreateAsync 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
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>>)
如果索引鍵存在,則以異步方式取得與此索引鍵相關聯的值,或者如果找不到索引鍵,則會使用提供的索引鍵和來自指定處理站的值產生新的專案。
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);
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)
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
- key
- Object
- factory
- Func<ICacheEntry,Task<TItem>>
- createOptions
- MemoryCacheEntryOptions
傳回
Task<TItem>
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應