/// <summary> /// Provides implementation of Remove method of the ICacheStorage interface. /// Removes an object from the store, specified by the passed in key /// </summary> /// <param name="key">key</param> /// <returns>object</returns> public override object Remove(object key) { try { lock (_itemDict.SyncRoot) { MmfObjectPtr info = (MmfObjectPtr)_itemDict[key]; if (info != null) { byte[] data = _internalStore.Remove(info); StoreItem item = StoreItem.FromBinary(data, CacheContext); _itemDict.Remove(key); IStorageEntry strEntry = item.Value as IStorageEntry; base.Removed(strEntry, Common.MemoryUtil.GetStringSize(key), strEntry.Type); return(item.Value); } } } catch (Exception e) { Trace.error("MmfStorageProvider.Remove()", e.ToString()); } return(null); }
/// <summary> /// Provides implementation of Add method of the ICacheStorage interface. Add the key /// value pair to the store. /// </summary> /// <param name="key">key</param> /// <param name="item">object</param> /// <returns>returns the result of operation.</returns> public override StoreAddResult Add(object key, IStorageEntry item, Boolean allowExtendedSize) { try { if (_itemDict.ContainsKey(key)) { return(StoreAddResult.KeyExists); } StoreStatus status = HasSpace((ISizable)item, Common.MemoryUtil.GetStringSize(key), allowExtendedSize); if (status == StoreStatus.HasNotEnoughSpace) { return(StoreAddResult.NotEnoughSpace); } byte[] buffer = StoreItem.ToBinary(key, item, CacheContext); lock (_itemDict.SyncRoot) { MmfObjectPtr info = _internalStore.Add(buffer); if (info == null) { return(StoreAddResult.NotEnoughSpace); } info.View.ParentStorageProvider = this; _itemDict.Add(key, info); base.Added(item, Common.MemoryUtil.GetStringSize(key)); } if (status == StoreStatus.NearEviction) { return(StoreAddResult.SuccessNearEviction); } } catch (OutOfMemoryException e) { Trace.error("OutofMemoryException::MmfStorageProvider.Add()", e.ToString()); return(StoreAddResult.NotEnoughSpace); } catch (Exception e) { Trace.error("General Exception::MmfStorageProvider.Add()", e.ToString()); return(StoreAddResult.Failure); } return(StoreAddResult.Success); }
/// <summary> /// Recupera o tamanho do item associado com a chave informada. /// </summary> /// <param name="key"></param> /// <returns></returns> public override int GetItemSize(object key) { try { MmfObjectPtr info = (MmfObjectPtr)_itemDict[key]; if (info != null) { return(((ISizable)StoreItem.FromBinary(_internalStore.Get(info), base.CacheContext).Value).Size); } } catch (Exception exception) { Trace.Error("MmfStorageProvider.GetItemSize()".GetFormatter(), exception.GetFormatter()); } return(0); }
/// <summary> /// Get the size of item stored in cache, specified by the passed in key /// </summary> /// <param name="key">key</param> /// <returns>item size</returns> public override int GetItemSize(object key) { try { MmfObjectPtr info = (MmfObjectPtr)_itemDict[key]; if (info != null) { byte[] data = _internalStore.Get(info); StoreItem item = StoreItem.FromBinary(data, CacheContext); return(((ISizable)item.Value).InMemorySize); } } catch (Exception e) { Trace.error("MmfStorageProvider.GetItemSize()", e.ToString()); } return(0); }
/// <summary> /// Adiciona um novo item. /// </summary> /// <param name="key">Chave do item.</param> /// <param name="item">Instancia do item.</param> /// <returns>Resultado da operação.</returns> public override StoreAddResult Add(object key, object item) { try { if (_itemDict.ContainsKey(key)) { return(StoreAddResult.KeyExists); } StorageProviderBase.StoreStatus status = base.HasSpace((ISizable)item); if (status == StorageProviderBase.StoreStatus.HasNotEnoughSpace) { return(StoreAddResult.NotEnoughSpace); } byte[] buffer = StoreItem.ToBinary(key, item, base.CacheContext); lock (_itemDict.SyncRoot) { MmfObjectPtr ptr = _internalStore.Add(buffer); if (ptr == null) { return(StoreAddResult.NotEnoughSpace); } ptr.View.ParentStorageProvider = this; _itemDict.Add(key, ptr); base.Added(item as ISizable); } if (status == StorageProviderBase.StoreStatus.NearEviction) { return(StoreAddResult.SuccessNearEviction); } } catch (OutOfMemoryException exception) { Trace.Error("OutofMemoryException::MmfStorageProvider.Add()".GetFormatter(), exception.GetFormatter()); return(StoreAddResult.NotEnoughSpace); } catch (Exception exception2) { Trace.Error("General Exception::MmfStorageProvider.Add()".GetFormatter(), exception2.GetFormatter()); return(StoreAddResult.Failure); } return(StoreAddResult.Success); }
/// <summary> /// Remove o item com base na chave informada. /// </summary> /// <param name="key">Chave do item que será removido.</param> /// <returns>Instancia do item removido.</returns> public override object Remove(object key) { try { lock (_itemDict.SyncRoot) { MmfObjectPtr info = (MmfObjectPtr)_itemDict[key]; if (info != null) { StoreItem item = StoreItem.FromBinary(_internalStore.Remove(info), base.CacheContext); _itemDict.Remove(key); base.Removed(item.Value as ISizable); return(item.Value); } } } catch (Exception exception) { Trace.Error("MmfStorageProvider.Remove()".GetFormatter(), exception.GetFormatter()); } return(null); }
/// <summary> /// Returns the MemArena against specific key. /// </summary> //I need it to update 'THIS' arena when ever next/previous references change [Asif Imam] public MemArena GetMemArena(object key) { MmfObjectPtr info = (MmfObjectPtr)_itemDict[key]; return(info.Arena); }
/// <summary> /// Provides implementation of Insert method of the ICacheStorage interface. Insert /// the key value pair to the store. /// </summary> /// <param name="key">key</param> /// <param name="item">object</param> /// <returns>returns the result of operation.</returns> public override StoreInsResult Insert(object key, IStorageEntry item, Boolean allowExtendedSize) { try { MmfObjectPtr info = (MmfObjectPtr)_itemDict[key]; IStorageEntry oldItem = null; if (info == null) { StoreAddResult res = Add(key, item, allowExtendedSize); switch (res) { case StoreAddResult.NotEnoughSpace: return(StoreInsResult.NotEnoughSpace); case StoreAddResult.Failure: return(StoreInsResult.Failure); } return(StoreInsResult.Success); } oldItem = (IStorageEntry)Get(key); StoreStatus status = HasSpace(oldItem as ISizable, (ISizable)item, Common.MemoryUtil.GetStringSize(key), allowExtendedSize); if (status == StoreStatus.HasNotEnoughSpace) { return(StoreInsResult.NotEnoughSpace); } byte[] buffer = StoreItem.ToBinary(key, item, CacheContext); lock (_itemDict.SyncRoot) { MmfObjectPtr newInfo = _internalStore.Insert(info, buffer); if (newInfo == null) { return(StoreInsResult.NotEnoughSpace); } else { if (newInfo.Arena != info.Arena) { _itemDict[key] = newInfo; _internalStore.Remove(info); } base.Inserted(oldItem, item, Common.MemoryUtil.GetStringSize(key)); } if (status == StoreStatus.NearEviction) { return(oldItem != null ? StoreInsResult.SuccessOverwriteNearEviction : StoreInsResult.SuccessNearEviction); } return(newInfo != null ? StoreInsResult.SuccessOverwrite : StoreInsResult.Success); } } catch (OutOfMemoryException e) { Trace.error("MmfStorageProvider.Insert()", e.ToString()); return(StoreInsResult.NotEnoughSpace); } catch (Exception e) { Trace.error("MmfStorageProvider.Insert()", e.ToString()); return(StoreInsResult.Failure); } }
/// <summary> /// Recupera a <see cref="MemArea"/> associada com a chave informada. /// </summary> /// <param name="key"></param> /// <returns></returns> public MemArea GetMemArea(object key) { MmfObjectPtr ptr = (MmfObjectPtr)_itemDict[key]; return(ptr.Area); }
/// <summary> /// Insere um novo item. /// </summary> /// <param name="key">Chave do item.</param> /// <param name="item">Instancia do item.</param> /// <returns>Resultado da operação.</returns> public override StoreInsResult Insert(object key, object item) { StoreInsResult notEnoughSpace; try { MmfObjectPtr info = (MmfObjectPtr)_itemDict[key]; object obj2 = null; if (info == null) { switch (this.Add(key, item)) { case StoreAddResult.NotEnoughSpace: return(StoreInsResult.NotEnoughSpace); case StoreAddResult.Failure: return(StoreInsResult.Failure); } return(StoreInsResult.Success); } obj2 = this.Get(key); StorageProviderBase.StoreStatus status = base.HasSpace(obj2 as ISizable, (ISizable)item); if (status == StorageProviderBase.StoreStatus.HasNotEnoughSpace) { notEnoughSpace = StoreInsResult.NotEnoughSpace; } else { byte[] buffer = StoreItem.ToBinary(key, item, base.CacheContext); lock (_itemDict.SyncRoot) { MmfObjectPtr ptr2 = _internalStore.Insert(info, buffer); if (ptr2 == null) { return(StoreInsResult.NotEnoughSpace); } if (ptr2.Area != info.Area) { _itemDict[key] = ptr2; _internalStore.Remove(info); } base.Inserted(obj2 as ISizable, item as ISizable); if (status == StorageProviderBase.StoreStatus.NearEviction) { return((obj2 != null) ? StoreInsResult.SuccessOverwriteNearEviction : StoreInsResult.SuccessNearEviction); } notEnoughSpace = (ptr2 != null) ? StoreInsResult.SuccessOverwrite : StoreInsResult.Success; } } } catch (OutOfMemoryException exception) { Trace.Error("MmfStorageProvider.Insert()".GetFormatter(), exception.GetFormatter()); notEnoughSpace = StoreInsResult.NotEnoughSpace; } catch (Exception exception2) { Trace.Error("MmfStorageProvider.Insert()".GetFormatter(), exception2.GetFormatter()); notEnoughSpace = StoreInsResult.Failure; } return(notEnoughSpace); }