示例#1
0
        /// <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
            {
                IStorageEntry oldItem = (IStorageEntry)Get(key);

                StoreStatus status = HasSpace((ISizable)item, Common.MemoryUtil.GetStringSize(key), allowExtendedSize);

                if (status == StoreStatus.HasNotEnoughSpace)
                {
                    return(StoreInsResult.NotEnoughSpace);
                }

                lock (_itemDict)
                {
                    object value = _internalStore.Insert(_itemDict[key], item, CacheContext);
                    if (value == null)
                    {
                        return(StoreInsResult.Failure);
                    }

                    _itemDict[key] = value;
                    SetStateChanged();

                    base.Inserted(oldItem, item, Common.MemoryUtil.GetStringSize(key));
                }
                if (status == StoreStatus.NearEviction)
                {
                    return(oldItem != null ? StoreInsResult.SuccessOverwriteNearEviction : StoreInsResult.SuccessNearEviction);
                }
                return(oldItem != null ? StoreInsResult.SuccessOverwrite : StoreInsResult.Success);
            }
            catch (OutOfMemoryException e)
            {
                Trace.error("FileSystemStorageProvider.Insert()", e.ToString());
                return(StoreInsResult.NotEnoughSpace);
            }
            catch (Exception e)
            {
                Trace.error("FileSystemStorageProvider.Insert()", e.ToString());
                return(StoreInsResult.Failure);
            }
        }
 /// <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)
 {
     try
     {
         object obj2 = this.Get(key);
         StorageProviderBase.StoreStatus status = base.HasSpace((ISizable)item);
         if (status == StorageProviderBase.StoreStatus.HasNotEnoughSpace)
         {
             return(StoreInsResult.NotEnoughSpace);
         }
         lock (_itemDict)
         {
             object obj3 = _internalStore.Insert(_itemDict[key], item, base.CacheContext);
             if (obj3 == null)
             {
                 return(StoreInsResult.Failure);
             }
             _itemDict[key] = obj3;
             this.SetStateChanged();
             base.Inserted(obj2 as ISizable, item as ISizable);
         }
         if (status == StorageProviderBase.StoreStatus.NearEviction)
         {
             return((obj2 != null) ? StoreInsResult.SuccessOverwriteNearEviction : StoreInsResult.SuccessNearEviction);
         }
         return((obj2 != null) ? StoreInsResult.SuccessOverwrite : StoreInsResult.Success);
     }
     catch (OutOfMemoryException exception)
     {
         Colosoft.Logging.Trace.Error("FileSystemStorageProvider.Insert()".GetFormatter(), exception.GetFormatter());
         return(StoreInsResult.NotEnoughSpace);
     }
     catch (Exception exception2)
     {
         Colosoft.Logging.Trace.Error("FileSystemStorageProvider.Insert()".GetFormatter(), exception2.GetFormatter());
         return(StoreInsResult.Failure);
     }
 }