/// <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 static IBlendedCache GetCache() { var contextCache = new HttpContextCache(); var volatileCache = new RuntimeMemoryCachingVolatileCache(); var longTermCache = new DictionaryLongTermCache(); var configuration = new BlendedCacheConfiguration() { DefaultCacheTimeout = new DefaultCacheTimeout() { VolatileTimeoutInSeconds = 5, LongTermTimeoutInSeconds = 10, } }; // this could be driven by the web.config return new BlendedCache.BlendedCache(contextCache, volatileCache, _dictionaryLongTermCache, configuration); }
private void Execute() { var longTermCache = new DictionaryLongTermCache(_cacheKey, _cachedItem); var cache = TestHelpers.GetCache(longTermCache: longTermCache); _contextCache = cache.GetContextCache(); _volatileCache = cache.GetVolatileCache(); _response = cache.Get<CachedData, Guid>(_lookupKey); _metrics = BlendedCacheMetricsStore.GetCachedItemMetrics<CachedData, Guid>(_lookupKey) ?? new Metrics(); }