コード例 #1
0
 /// <summary>
 /// Gets the requested type of item(s) from the memory cache. If unavailable;
 /// Runs the provided function to obtain the items and caches them.
 /// </summary>
 /// <param name="func">The delegate to call to retrieve the data if not available in the cache.</param>
 /// <param name="cancellationToken">The cancellation token used to determine if the asynchronous operation should be cancelled.</param>
 /// <returns>The item(s) from the cache.</returns>
 public virtual async Task <T> GetOrCreateAsync(
     Func <CancellationToken, Task <T> > func,
     CancellationToken cancellationToken = default)
 => await MemoryCache.GetOrCreateAsync(CachedTypeKey <T> .Instance, async (cacheEntry) =>
 {
     cacheEntry.SetOptions(CacheEntryOptionsProvider.GetCacheEntryOption <T>().MemoryCacheEntryOptions);
     return(await func(cancellationToken));
 });
コード例 #2
0
 public static CachedTypeOption GetCacheEntryOption(this ICachedTypeOptionsProvider cacheEntryOptionsProvider, Type type)
 => cacheEntryOptionsProvider.GetCacheEntryOption(type.FullName);
コード例 #3
0
 public static CachedTypeOption GetCacheEntryOption <T>(this ICachedTypeOptionsProvider cacheEntryOptionsProvider)
 => cacheEntryOptionsProvider.GetCacheEntryOption(typeof(T));