public void CacheAddsItem() { using (var cache = new TimeToLiveCache <long, object>(5000)) { var item = new TimeToLiveTestItem { Id = 1 }; cache.AddOrUpdate(item.Id, item); Assert.IsTrue(cache.Contains(item.Id)); } }
public void CacheEvictsItemIfTieoutReached() { using (var cache = new TimeToLiveCache <long, object>()) { var item = new TimeToLiveTestItem { Id = 1 }; cache.AddOrUpdate(item.Id, item, 100); Thread.Sleep(500); Assert.IsFalse(cache.Contains(item.Id)); } }
public void CacheRestartsTimerForItem() { using (var cache = new TimeToLiveCache <long, object>()) { var item = new TimeToLiveTestItem { Id = 1 }; cache.AddOrUpdate(item.Id, item, 500); cache.AddOrUpdate(item.Id, item, 2000, true); Thread.Sleep(500); Assert.IsTrue(cache.Contains(item.Id)); } }
public void CacheDoesNotEvictItemBeforeTimeoutReached() { const int defaultTimeout = 500; const int customTimeout = 30000; using (var cache = new TimeToLiveCache <long, object>(defaultTimeout)) { var item = new TimeToLiveTestItem { Id = 1 }; cache.AddOrUpdate(item.Id, item, customTimeout); Thread.Sleep(defaultTimeout); Assert.IsTrue(cache.Contains(item.Id)); } }