public void WhenAbsoluteShouldHandleAbsoluteTimeSpan() { var cached = 0; // each cached value has a lifetime of the specified duration Func <int> retrieve = () => _cacheManager.Get("testItem", ctx => { ctx.Monitor(_clock.When(TimeSpan.FromSeconds(1))); return(++cached); }); Assert.Equal(retrieve(), 1); for (var i = 0; i < 10; i++) { Assert.Equal(retrieve(), 1); } _clock.Advance(TimeSpan.FromSeconds(1)); for (var i = 0; i < 10; i++) { Assert.Equal(retrieve(), 2); } _clock.Advance(TimeSpan.FromSeconds(1)); for (var i = 0; i < 10; i++) { Assert.Equal(retrieve(), 3); } }
public T GetCached <T>(string CachedKey, Func <T> func, TimeSpan timespan) { return(CacheManager.Get(CachedKey, ctx => { ctx.Monitor(StubClock.When(timespan)); return func(); })); }
public T GetCached <T>(string CachedKey, Func <T> func, TimeSpan timespan, bool Cach = true) { if (!Cach) { return(func()); } return(CacheManager.Get(CachedKey, ctx => { ctx.Monitor(Clock.When(timespan)); return func(); })); }