public void TestCacheEnumerator() { IntObjectCache cache = new IntObjectCache(16); for (int i = 0; i < 10; ++i) { cache.CacheObject(i, i); } int count = 0; foreach (int i in cache) { ++count; } Assert.AreEqual(10, count); for (int i = 0; i < 10; ++i) { cache.CacheObject(i + 10, i); } count = 0; foreach (int i in cache) { ++count; } Assert.AreEqual(cache.Size, count); }
static IntInternalizer() { _intCacheLock = new SpinWaitLock(); _intCache = new IntObjectCache(_intCacheSize); for (int i = 0; i < _intCacheSize; ++i) { _intCache.CacheObject(i, i); } }
public void StressCaching() { const int cacheSize = 1000; IntObjectCache cache = new IntObjectCache(cacheSize); Random rnd = new Random(); for (int i = 0; i < 100000000; ++i) { int next = rnd.Next(cacheSize * 2); if (cache.TryKey(next) == null) { cache.CacheObject(next, i); } } Console.WriteLine("Cache hit rate = " + cache.HitRate().ToString()); }