コード例 #1
0
        public T SendAndReadCached <T>(CachedHttpRequestMessage <T> requestMessage, TimeSpan cacheDuration) where T : class
        {
            _watch.Reset();
            _watch.Start();

            var cache    = MemoryCache.Default;
            var cacheKey = _mandatorId + "_" + requestMessage.GetCacheKey();

            if (!cache.Contains(cacheKey))
            {
                cache.Add(cacheKey, SendAndRead <T>(requestMessage, false),
                          DateTimeOffset.Now.Add(cacheDuration));
            }
            else
            {
                ElapsedMillisecondsInLastCall = 0;
            }

            var result = cache.Get(cacheKey) as T;

            _watch.Stop();
            ElapsedMillisecondsInLastCall = _watch.ElapsedMilliseconds;

            return(result);
        }
コード例 #2
0
 internal async Task <T> SendAndReadAsyncCached <T>(CachedHttpRequestMessage <T> requestMessage) where T : class
 {
     return(await SendAndReadAsyncCached(requestMessage, TimeSpan.FromSeconds(CacheDurationInSeconds)));
 }
コード例 #3
0
 public T SendAndReadCached <T>(CachedHttpRequestMessage <T> requestMessage) where T : class
 {
     return(SendAndReadCached(requestMessage, TimeSpan.FromSeconds(CacheDurationInSeconds)));
 }