private string GetSerializedValue(DataCacheItem dataCacheItem) { PropertyInfo getSerializedValueMethod = dataCacheItem.GetType().GetProperty("SerializedValue", BindingFlags.NonPublic | BindingFlags.Instance); StringBuilder sb = new StringBuilder(1024); object[] getKeysParams = new object[] { }; byte[][] serializedValueAs2DByteArray = getSerializedValueMethod.GetValue(dataCacheItem) as byte[][]; foreach (byte[] row in serializedValueAs2DByteArray) { foreach (byte b in row) { if (b > 0) { char c = (char)b; if (char.IsControl(c)) { sb.Append(" "); } else { sb.Append(c); } } } } return(sb.ToString()); }
private void SelectItem(int selectedItemIndex) { if (selectedItemIndex < 0 || selectedItemIndex >= _cacheInteraction.FilteredKeyCount) { ClearCacheItemDetails(); return; } _selectedKey = _cacheInteraction.GetItem(selectedItemIndex); try { DataCacheItem response = _cacheInteraction.GetCacheItem(_selectedVersion, _selectedKey); try { object responseValue = response.Value; lblItemTypeValue.Text = responseValue.GetType().GetCSharpRepresentation(true); txtValue.Text = JsonConvert.SerializeObject(response.Value, Formatting.Indented, _settings); } catch (SerializationException) { txtValue.Text = "Caught SerializationException, Serialized data is:" + Environment.NewLine + GetSerializedValue(response); } catch (Exception) { try { txtValue.Text = "Caught Exception, serialized data is: " + Environment.NewLine + GetSerializedValue(response); } catch { txtValue.Text = "Cannot display cache item"; } } lblCacheNameValue.Text = response.CacheName; lblExtensionTimeoutValue.Text = string.Format("{0:N0} seconds", response.ExtensionTimeout.TotalSeconds); lblRegionNameValue.Text = response.RegionName; lblSizeValue.Text = string.Format("{0:N0} bytes", response.Size); lblTimeoutValue.Text = string.Format("{0:N0} seconds", response.Timeout.TotalSeconds); btnRemove.Enabled = true; } catch { txtValue.Text = string.Format("Cache item {0} for version {1} has expired or been removed.", _selectedKey, _selectedVersion); lblCacheNameValue.Text = "Expired"; lblExtensionTimeoutValue.Text = "Expired"; lblRegionNameValue.Text = "Expired"; lblSizeValue.Text = "Expired"; lblTimeoutValue.Text = "Expired"; } tsslActionStatus.Text = ""; lblKeyNameValue.Text = _selectedKey; }
private void GetCacheItem(string objectID) { rtbGetCacheItem.Clear(); DataCacheItem dcItem = new DataCacheItem(); if (myCache == null) { UpdateStatus("First click Connect To Cache"); return; } try { if (objectID != null) { txtGetCacheItem.Text = objectID; txtMonitorItem.Text = objectID; txtMonitorCacheItem.Text = objectID; dcItem = myCache.GetCacheItem(objectID); if (dcItem != null) { UpdateStatus("Retrived item from cache"); txtMonitorCacheItemValue.Text = dcItem.Value.ToString(); rtbGetCacheItem.AppendText("\r\n" + "Last Updated at " + DateTime.Now.ToLongTimeString()); rtbGetCacheItem.AppendText("\r" + "CacheName: " + dcItem.CacheName); rtbGetCacheItem.AppendText("\r" + "Key:" + dcItem.Key); rtbGetCacheItem.AppendText("\r" + "RegionName: " + dcItem.RegionName); rtbGetCacheItem.AppendText("\r" + "Size: " + dcItem.Size); //lstGetCacheItem.Items.Add(dcItem.Tags); rtbGetCacheItem.AppendText("\r" + "Timeout: " + dcItem.Timeout); rtbGetCacheItem.AppendText("\r" + "Value: " + dcItem.Value); rtbGetCacheItem.AppendText("\r" + "Version: " + dcItem.Version); } else { UpdateStatus("Retrived NULL from cache"); txtMonitorCacheItemValue.Text = "Retrived NULL from cache"; } } } catch (Exception ex) { //MessageBox.Show(ex.Message); //MessageBox.Show(ex.StackTrace); HandleException(ex); } }
public void InvalidateItem(string key) { key = GetCacheKey(key); DataCacheItem item = _cache.GetCacheItem(key); _cache.Remove(key); foreach (var tag in item.Tags) { _cache.Remove(key, tag.ToString()); } }
//Update public void Update(DataCacheObject obj) { DataCache dc = GetDataCache(obj.Type.ToString()); if (!Contains(obj)) { return; } DataCacheItem dci = dc.GetCacheItem(GetKey(obj)); dc.Put(GetKey(obj), obj.Data, dci.Version, dci.Timeout); }
public void Put(DataCacheObject obj) { DataCacheItem dci = new DataCacheItem(); try { DataCache dc = GetDataCache(obj.Type.ToString()); dc.Put(GetKey(obj), obj.Data, TimeSpan.FromSeconds(obj.CacheTime), obj.Region); } catch (DataCacheException ex) { Logger.LogException(obj.Method + " ~ " + String.Format("cached_value:{0}; new_value:{1}", dci.Value, obj.Data), ex); } }
//Update public void Update(DataCacheObject obj) { try{ DataCache dc = GetDataCache(obj.Type.ToString()); if (!Contains(obj)) { return; } DataCacheItem dci = dc.GetCacheItem(GetKey(obj)); dc.Put(GetKey(obj), obj.Data, dci.Version, dci.Timeout); } catch (Exception ex) { Logger.LogException("APPFABRICCACHEPROVIDERSYSTEMREGIONS_UPDATE", ex); } }
public void Update(DataCacheObject obj) { try { if (!Contains(obj)) { return; } DataCache dc = GetDataCache(obj.Type.ToString()); DataCacheItem dci = dc.GetCacheItem(GetKey(obj), obj.Region); dc.Put(GetKey(obj), obj.Data, dci.Timeout, obj.Region); } catch (Exception ex) { Logger.LogException(obj.Method, ex); } }
public void Update(DataCacheObject obj) { DataCacheItem dci = new DataCacheItem(); try { DataCache dc = GetDataCache(obj.Type.ToString()); if (!Contains(obj)) { return; } dci = dc.GetCacheItem(GetKey(obj), obj.Region); dc.Put(GetKey(obj), obj.Data, dci.Version, dci.Timeout, obj.Region); } catch (DataCacheException ex) { Logger.LogException(obj.Method + " ~ " + String.Format("cached_value:{0}; new_value:{1}", dci.Value, obj.Data), ex); } }
public void Update(DataCacheObject obj) { DataCacheItem dci = new DataCacheItem(); try { DataCache dc = GetDataCache(obj.Type.ToString()); if (!Contains(obj)) return; dci = dc.GetCacheItem(GetKey(obj), obj.Region); dc.Put(GetKey(obj), obj.Data, dci.Version, dci.Timeout, obj.Region); } catch (DataCacheException ex) { Logger.LogException(obj.Method + " ~ " + String.Format("cached_value:{0}; new_value:{1}", dci.Value, obj.Data), ex); } }
public LocalCacheItemCallbackWrapper(string key, DataCacheItem cachedItem, Func<object, object> callback, object callBackState, TimeSpan timeToLive) { this.Key = key; this.CachedItem = cachedItem; this.Callback = callback; this.CallBackState = callBackState; this.TimeToLive = timeToLive; }
private DataCacheItemVersion SetItemInternal(string key, DataCacheItem item, TimeSpan timeToLive) { if (String.IsNullOrWhiteSpace(key)) { throw new ArgumentNullOrWhiteSpaceException("key"); } if (item == null) { throw new ArgumentNullException("item"); } if (this.client.Store(StoreMode.Set, this.BuildKey(key), item, timeToLive)) { return item.Version; } return null; }
private DataCacheItemVersion SetItemInternal(string key, object value, TimeSpan timeToLive) { if (String.IsNullOrWhiteSpace(key)) { throw new ArgumentNullOrWhiteSpaceException("key"); } if (value == null) { throw new ArgumentNullException("value"); } DataCacheItem item = new DataCacheItem(); item.Version = new DataCacheItemVersion(Guid.NewGuid()); item.Value = value; item.CreateTime = DateTime.Now; IDebugableCachedItem valueAsDebugableItem = value as IDebugableCachedItem; if (valueAsDebugableItem != null) { valueAsDebugableItem.CreateTime = DateTime.Now; valueAsDebugableItem.LastUpdateTime = DateTime.Now; valueAsDebugableItem.TimeToLive = timeToLive; valueAsDebugableItem.SourceApp = RunContext.AppName; valueAsDebugableItem.SourceAppVersion = RunContext.AppVersion; valueAsDebugableItem.SourceMachine = RunContext.Machine; } if (this.client.Store(StoreMode.Set, this.BuildKey(key), item, timeToLive)) { return item.Version; } return null; }
public TimeSpan TimeRemaining(string item) { DataCacheItem DCitem = cache.GetCacheItem(item); return(DCitem.Timeout); }