public void ReturnsTrueWhenHasCache() { var cache = new LazyResetCache <string>(new TimeSpan(1, 0, 0)); cache.Init(() => "piyo"); Assert.True(cache.Exists(), "should have something"); }
public void ReturnsCachedValue() { var cache = new LazyResetCache <string>(new TimeSpan(1, 0, 0)); cache.Init(() => "piyo"); Assert.Equal("piyo", cache.Get()); }
public async void Expires() { var cache = new LazyResetCache <int>((new TimeSpan(0, 0, 0, 0, 100))); var i = 0; cache.Init(() => { Task.Delay(100).Wait(); return(i); }); Assert.Equal(0, cache.Get()); await Task.Delay(200); i++; Assert.Equal(0, cache.Get()); await Task.Delay(200); Assert.Equal(1, cache.Get()); }
public IActionResult Index() { var cached = cache.Exists(); if (!cached) { cache.Init(() => { Console.WriteLine("Start Set(): " + DateTime.Now.ToString()); Task.Delay(1000).Wait(); var time = DateTime.Now.ToString(); Console.WriteLine("Complete Set()." + time); return(time); }); } ViewData["Requested"] = DateTime.Now.ToString(); ViewData["Cached"] = cache.Get(); ViewData["IsCached"] = cached; return(View()); }
public void Success() { var cache = new LazyResetCache <string>(new TimeSpan(1, 0, 0)); cache.Init(() => "hoge"); }