private void CacheUpdateAction(RedisChannel channel, RedisValue message) { var updateNotification = _serialize.Deserialize <CacheNotificationObject>(message); _localCache.Remove(updateNotification.CacheKey); _localCache.Set(updateNotification.CacheKey, updateNotification.CacheValue, updateNotification.Expiration); }
public object Generate() { var list = _demoHelper.GenerateDemoObjects(1000); var key = string.Format(KeyFormat, _demoHelper.MemberName, Guid.NewGuid()); _littleThunder.Set(key, list, CacheTime.OneDay, false); return(list); }
public void OnBeforeGet(string key, TimeSpan timeout) { _logger.Log(LogLevel.Trace, string.Format("GreatEagle OnBeforeGet {0}", key)); if (_localCacheProvider == null) { return; } if (_localCacheProvider.Exists(key)) { return; } var tempKey = string.Format(TempItemFormat, key); // Check key exists on master if (!_remoteCacheProvider.Exists(key)) { // Key not exits // Check temp key exists on master if (!_remoteCacheProvider.Exists(tempKey)) { return; // Temp key not exits } // Temp key exists, so wait for tribe member to finish his job ThreadHelper.WaitFor(timeout); } //else //{ // // TODO: Investigate // // Key exists // // Check also temp key exists to be sure is ongoing update operation exists // if (_remoteCacheProvider.Exists(tempKey)) // { // // If so wait for update // ThreadHelper.WaitFor(timeout); // } //} var task = new Task <InMemoryCacheItem>(() => { var it = _remoteCacheProvider.Get <InMemoryCacheItem>(key, timeout); return(it); }); task.Start(); task.Wait(timeout); if (!task.IsCompleted) { return; } var item = task.Result; if (item == null) { return; } _localCacheProvider.Set(key, item.ValueObject, item.GetExpireTimeSpan()); }
internal void LoadFromRemoteInternal() { var keys = _remoteCacheProvider.AllKeys(); if (keys != null) { foreach (var key in keys) { // TODO: Timeout should be configuration parameter var item = _remoteCacheProvider.Get <InMemoryCacheItem>(key, TimeSpan.Zero, true); _localCacheProvider.Set(key, item.ValueObject, item.ExpiresAtTimeSpan, true); } } _subscriptionManager.StartSubscription(); }
public List <DemoObject> FillSomeDemoObjectToLocalCache(string key) { var list = _demoHelper.GenerateDemoObjects(1000); _localCache.Set(key, list, CacheTime.FifteenMinutes); return(list); }
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); }