protected virtual async Task <TCachedResult> GetCachedResultAsync(TContext context, IAsyncDecorator decorator, IAsyncQueryCache <TCacheEntryOptions> queryCache, CacheOption cacheOption = CacheOption.Default) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (decorator == null) { throw new ArgumentNullException(nameof(decorator)); } if (queryCache == null) { throw new ArgumentNullException(nameof(queryCache)); } State.Inject(context); Task <TCachedResult> queryAsync() => decorator.Decorate(this, () => QueryAsync(context)); if (cacheOption == CacheOption.Default) { return(State.CachedResult = await queryCache.GetAsync(queryAsync, State.CacheInfo, State.GetCacheEntryOptions).ConfigureAwait(false)); } State.CachedResult = await queryAsync().ConfigureAwait(false); await queryCache.SetAsync(State.CachedResult, State.CacheInfo, State.GetCacheEntryOptions).ConfigureAwait(false); return(State.CachedResult); }
public virtual Task UpdateCachedResultAsync(IAsyncQueryCache <TCacheEntryOptions> queryCache) { if (queryCache == null) { throw new ArgumentNullException(nameof(queryCache)); } return(queryCache.SetAsync(State.CachedResult, State.CacheInfo, State.GetCacheEntryOptions)); }