public IEnumerable <TestCaseData> Caches( ) { ICacheFactory inner = new DictionaryCacheFactory( ); // Factories to test ICacheFactory [] factories = new ICacheFactory [] { new PerTenantCacheFactory { Inner = inner }, new PerTenantNonSharingCacheFactory { Inner = inner }, new DelayedInvalidateCacheFactory { Inner = inner }, }; // Create test data // Note: We return factories instead of caches, because NUnit reuses the same instances if the test is rerun. :p foreach (ICacheFactory factory in factories) { string name = factory.GetType( ).Name.Replace("Factory", ""); yield return(new TestCaseData(name, factory)); } }
public EDC.Cache.ICache <TKey, TValue> Create <TKey, TValue>(string cacheName) { var result = new DictionaryCacheFactory().Create <TKey, TValue>(cacheName); Inner = (EDC.Cache.ICache <string, string>)result; return(result); }
public IEnumerable <TestCaseData> Caches( ) { ICacheFactory inner = new DictionaryCacheFactory( ); // Factories to test ICacheFactory [] factories = new ICacheFactory [] { new BlockIfPendingCacheFactory { Inner = inner }, new DictionaryCacheFactory( ), new LoggingCacheFactory { Inner = inner }, new LruCacheFactory { Inner = inner, MaxSize = 100 }, new ThreadSafeCacheFactory { Inner = inner }, new TimeoutCacheFactory { Inner = inner, Expiration = TimeSpan.FromMinutes(1) }, new TransactionAwareCacheFactory { Inner = inner, Private = inner }, new StochasticCacheFactory { Inner = inner, MaxSize = 100 } }; // Create test data // Note: We return factories instead of caches, because NUnit reuses the same instances if the test is rerun. :p foreach (ICacheFactory factory in factories) { string name = factory.GetType( ).Name.Replace("Factory", ""); yield return(new TestCaseData(name, factory)); } }
/// <summary> /// Create cache, according to the configuration of the factory. /// </summary> /// <typeparam name="TKey">Type of cache key.</typeparam> /// <typeparam name="TValue">Type of cache value.</typeparam> /// <param name="cacheName">Name of the cache.</param> /// <returns> /// A cache. /// </returns> /// <exception cref="System.InvalidOperationException"></exception> public ICache <TKey, TValue> Create <TKey, TValue>(string cacheName) { ICacheFactory fact = null; // // The first caches encountered will be lowest in the stack // if (Redis) { if (ConfigurationSettings.GetCacheConfigurationSection().RedisCacheSettings.Enabled) { fact = new RedisCacheFactory { Inner = null, CompressKey = RedisKeyCompression, CompressValue = RedisValueCompression, KeyExpiry = RedisKeyExpiry }; } else { Diagnostics.EventLog.Application.WriteWarning("Cache '{0}' requested a Redis layer but was denied due to the SoftwarePlatform.config settings.", cacheName); } } if (Dictionary) { fact = new DictionaryCacheFactory { Inner = fact }; } if (MaxCacheEntries > 0) { // Attempt to get the maximum value from the configuration settings int configMaxCacheSize = GetMaximumCacheSize(cacheName); if (configMaxCacheSize > 0) { MaxCacheEntries = configMaxCacheSize; } if (Lru) { fact = new LruCacheFactory { Inner = fact, MaxSize = MaxCacheEntries, EvictionFrequency = LruEvictionFrequency }; } else { fact = new StochasticCacheFactory { Inner = fact, MaxSize = MaxCacheEntries }; } } if (ExpirationInterval != TimeSpan.Zero) { fact = new TimeoutCacheFactory { Inner = fact, Expiration = ExpirationInterval, EvictionFrequency = TimeoutEvictionFrequency }; } if (TransactionAware) { fact = new TransactionAwareCacheFactory { Inner = fact }; } if (Logging) { fact = new LoggingCacheFactory { Inner = fact, MaxSize = MaxCacheEntries }; } if (fact != null && (ThreadSafe && !fact.ThreadSafe)) { fact = new ThreadSafeCacheFactory { Inner = fact }; } if (BlockIfPending || DelayedInvalidates) { fact = new BlockIfPendingCacheFactory { Inner = fact }; } if (DelayedInvalidates) { // Must be below BlockIfPending fact = new DelayedInvalidateCacheFactory { Inner = fact, ExpirationInterval = new TimeSpan(0, 1, 0) }; } if (MetadataCache) { fact = new MetadataCacheFactory { Inner = fact }; } if (IsolateTenants) { fact = new PerTenantNonSharingCacheFactory { Inner = fact }; } if (Distributed) { fact = new RedisPubSubCacheFactory <TKey>(fact, IsolateTenants); } // Final safety check if (fact == null || (ThreadSafe && !fact.ThreadSafe)) { throw new InvalidOperationException(); } var cache = fact.Create <TKey, TValue>(cacheName); return(cache); }