public void CacheMultipleItems() { ICache <string, string> cache = Caffeine <string, string> .Builder() .SpecifyMaximumSize(2) .RecordStats() //.ExpireAfterWrite(new TimeSpan(0, 1, 0)) //.RefreshAfterWrite(new TimeSpan(0, 1, 0)) .Build(); cache.Add("test", "hello world"); cache.Add("new", "secondItem"); string rval = cache.TryGetValue("new"); Assert.True(!string.IsNullOrWhiteSpace(rval)); }
public void CacheAndRemoveItem() { ICache <string, string> cache = Caffeine <string, string> .Builder() .SpecifyMaximumSize(100) .RecordStats() //.ExpireAfterWrite(new TimeSpan(0, 1, 0)) //.RefreshAfterWrite(new TimeSpan(0, 1, 0)) .Build(); cache.Add("test", "hello world"); cache.Invalidate("test"); string rval = cache.TryGetValue("test"); Assert.True(string.IsNullOrWhiteSpace(rval)); }
public void CacheItem() { ICache <string, string> cache = Caffeine <string, string> .Builder() .SpecifyMaximumSize(100) .RecordStats() //.ExpireAfterWrite(new TimeSpan(0, 1, 0)) //.RefreshAfterWrite(new TimeSpan(0, 1, 0)) .Build(); cache.Add("test", "hello world"); //Thread.Sleep(5000); string rval = cache.TryGetValue("test"); output.WriteLine(cache.Stats.ToString()); Assert.Equal("hello world", rval); }