Пример #1
0
 /// <summary>
 /// Executes the specified action asynchronously within the cache policy and returns the result.
 /// </summary>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="action">The action to perform.</param>
 /// <param name="context">Execution context that is passed to the exception policy; defines the cache key to use in cache lookup.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <param name="continueOnCapturedContext">Whether to continue on a captured synchronization context.</param>
 /// <returns>The value returned by the action, or the cache.</returns>
 public override Task <TResult> ExecuteAsync <TResult>(Func <Context, CancellationToken, Task <TResult> > action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
 {
     return(CacheEngine.ImplementationAsync <TResult>(
                _asyncCacheProvider.AsyncFor <TResult>(),
                _ttlStrategy,
                _cacheKeyStrategy,
                action,
                context,
                cancellationToken,
                continueOnCapturedContext,
                _onCacheGet,
                _onCacheMiss,
                _onCachePut,
                _onCacheGetError,
                _onCachePutError));
 }
Пример #2
0
        internal override Task <TResult> ExecuteAsyncInternal <TResult>(Func <Context, CancellationToken, Task <TResult> > action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
        {
            if (_asyncCacheProvider == null)
            {
                throw new InvalidOperationException("Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.");
            }

            return(CacheEngine.ImplementationAsync <TResult>(
                       _asyncCacheProvider.AsyncFor <TResult>(),
                       _ttlStrategy.For <TResult>(),
                       _cacheKeyStrategy,
                       action,
                       context,
                       cancellationToken,
                       continueOnCapturedContext,
                       _onCacheGet,
                       _onCacheMiss,
                       _onCachePut,
                       _onCacheGetError,
                       _onCachePutError));
        }