Exemplo n.º 1
0
        public virtual Task EvictCachedResultAsync(IAsyncQueryCache <TCacheEntryOptions> queryCache)
        {
            if (queryCache == null)
            {
                throw new ArgumentNullException(nameof(queryCache));
            }

            return(queryCache.EvictAsync(State.CacheInfo.Key));
        }
Exemplo n.º 2
0
        public virtual Task UpdateCachedResultAsync(IAsyncQueryCache <TCacheEntryOptions> queryCache)
        {
            if (queryCache == null)
            {
                throw new ArgumentNullException(nameof(queryCache));
            }

            return(queryCache.SetAsync(State.CachedResult, State.CacheInfo, State.GetCacheEntryOptions));
        }
Exemplo n.º 3
0
        public virtual async Task <TTransformedResult> ExecuteAsync(TContext context, IAsyncDecorator decorator, IAsyncQueryCache <TCacheEntryOptions> queryCache, CacheOption cacheOption = CacheOption.Default)
        {
            var cachedResult = await GetCachedResultAsync(context, decorator, queryCache, cacheOption).ConfigureAwait(false);

            return(await TransformCachedResultAsync(cachedResult).ConfigureAwait(false));
        }
Exemplo n.º 4
0
 public virtual Task <TResult> ExecuteAsync(TContext context, IAsyncDecorator decorator, IAsyncQueryCache <TCacheEntryOptions> queryCache, CacheOption cacheOption = CacheOption.Default) =>
 GetCachedResultAsync(context, decorator, queryCache, cacheOption);
Exemplo n.º 5
0
        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);
        }