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 void EnsureCallbackThrottled( ) { var innerFactory = new DummyCacheFactory( ); EDC.Cache.ICache <string, string> cache = CreateCache(innerFactory, new TimeSpan(0, 0, 1)); string key = "1"; int callCount = 0; Action action = () => { string result; cache.TryGetOrAdd(key, out result, key1 => { Interlocked.Increment(ref callCount); return("A"); }); cache.Remove(key); }; Stopwatch sw = new Stopwatch( ); sw.Start( ); int runCount = 0; while (sw.ElapsedMilliseconds < 3000) { action( ); Thread.Sleep(10); Interlocked.Increment(ref runCount); } Assert.That(runCount, Is.GreaterThan(250).And.LessThan(350)); Assert.That(callCount, Is.GreaterThan(1).And.LessThan(6)); }