public List <DemoObject> GetSomeDemoObjectFromLocal(string key) { var list = _localCache.Get <List <DemoObject> >(key, TimeSpan.FromSeconds(3), false); Assert.NotNull(list); return(list); }
public IActionResult Index() { TimeSpan ts = TimeSpan.FromMinutes(5); //ViewBag.Cache = _localCache.Get("Test", () => "123", ts).ToString(); ViewBag.Cache = _localCache.Get("Test", () => { return(_remoteCache.Get("Test", () => _service.Get(), ts)); }, ts).ToString(); return(View()); }
void DoSomethingExpensive() { var list = _localCache.Get("personlist", TimeSpan.FromSeconds(3), () => { var result = new List <DemoObject>(_demoHelper.GenerateDemoObjects(1000)); return(result); }, TimeSpan.FromMinutes(15), false); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed : Sake of Demo list.OrderBy(o => o.CreatedAt); }
public void When_set_som_objects_it_should_call_CacheManager_and_when_get_it_back_it_should_be_same_instance() { var list = _demoHelper.GenerateDemoObjects(1000); _cache.Set(DemoObjectListKey, list, CacheTime.FifteenMinutes); Thread.Sleep(500); var item = new InMemoryCacheItem(list, CacheTime.FifteenMinutes); Assert.AreEqual(item, _onBeforeSetItem); Assert.AreEqual(DemoObjectListKey, _onBeforeSetKey); Assert.AreEqual(DemoObjectListKey, _onAfterSetKey); //_mockCacheManager.Received().OnBeforeSet(Arg.Is(DemoObjectListKey), Arg.Any<InMemoryCacheItem>()); //_mockCacheManager.Received().OnAfterSet(Arg.Is(DemoObjectListKey)); var cachedList = _cache.Get <List <DemoObject> >(DemoObjectListKey, TimeSpan.FromSeconds(3)); Thread.Sleep(500); Assert.AreEqual(DemoObjectListKey, _onBeforeGetKey); Assert.AreEqual(DemoObjectListKey, _onAfterGetKey); Assert.AreEqual(TimeSpan.FromSeconds(3), _onBeforeGetTimeout); Assert.NotNull(cachedList); Assert.AreSame(list, cachedList); }
public object Get(string id) { var item = _littleThunder.Get <List <DemoObject> >(id, TimeSpan.FromSeconds(3), false); return(item); }