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 InMemoryCacheItem GetSomeDemoObjectFromRemote(string key) { var item = _remoteCache.Get <InMemoryCacheItem>(key, TimeSpan.FromSeconds(3), false); Assert.NotNull(item); return(item); }
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()); }