/// <summary> /// Will get a blended cache under the default conditions. /// </summary> /// <returns></returns> public static BlendedCache GetCache(IContextCache contextCache = null, IVolatileCache volatileCache = null, ILongTermCache longTermCache = null, IBlendedCacheConfiguration configuration = null, bool initialFlushMode = false) { if(contextCache == null) contextCache = new DictionaryContextCache(); if(volatileCache == null) volatileCache = new DictionaryVolatileCache(); if(longTermCache == null) longTermCache = new DictionaryLongTermCache(); if(configuration == null) configuration = new BlendedCacheConfiguration(); var cache = new BlendedCache(contextCache, volatileCache, longTermCache, configuration); if (initialFlushMode) cache.GetType().GetField("_flushMode", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(cache, true); return cache; }
private void Execute() { var volatileCache = new DictionaryVolatileCache(_cacheKey, _cachedItem); var cache = TestHelpers.GetCache(volatileCache: volatileCache); _contextCache = cache.GetContextCache(); _response = cache.Get<CachedData>(_lookupKey); _metrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, string>(_lookupKey) ?? new Metrics(); }