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); }
internal async Task <T> SendAndReadAsyncCached <T>(CachedHttpRequestMessage <T> requestMessage) where T : class { return(await SendAndReadAsyncCached(requestMessage, TimeSpan.FromSeconds(CacheDurationInSeconds))); }
public T SendAndReadCached <T>(CachedHttpRequestMessage <T> requestMessage) where T : class { return(SendAndReadCached(requestMessage, TimeSpan.FromSeconds(CacheDurationInSeconds))); }