Esempio n. 1
0
        /// <inheritdoc />
        public Task <object> HandleMethodCall(MethodInfo targetMethod, object[] args, Func <Task <object> > innerHandler)
        {
            var cachingTime = _cachingStrategy.GetCachingTime(targetMethod, args);

            if (cachingTime <= TimeSpan.Zero)
            {
                return(innerHandler());
            }

            var contextData = new Dictionary <string, object>
            {
                { ContextualTtl.TimeSpanKey, cachingTime }
            };

            return(_retryPolicy.ExecuteAsync((context, ct) => innerHandler(),
                                             new Context(GetExecutionKey(targetMethod, args), contextData), default));
        }
Esempio n. 2
0
        /// <inheritdoc />
        public async Task <object> HandleMethodCall(MethodInfo targetMethod, object[] args, Func <Task <object> > innerHandler)
        {
            var cachingTime = _cachingStrategy.GetCachingTime(targetMethod, args);

            if (cachingTime <= TimeSpan.Zero)
            {
                return(await innerHandler());
            }

            var contextData = new Dictionary <string, object>
            {
                { ContextualTtl.TimeSpanKey, cachingTime }
            };

            string cacheKey = GetExecutionKey(targetMethod, args);

            using (var readLock = await _readerWriterLock.ReaderLockAsync())
            {
                _cacheKeys[cacheKey] = true;
                return(await _retryPolicy.ExecuteAsync(async (context, ct) => await innerHandler(),
                                                       new Context(cacheKey, contextData), default));