/// <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> /// 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); }