Пример #1
0
        /// <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);
                }

                lock (_itemDict)
                {
                    object value = _internalStore.Add(key, item, CacheContext);
                    if (value != null)
                    {
                        _itemDict.Add(key, value);
                        SetStateChanged();

                        base.Added(item, Common.MemoryUtil.GetStringSize(key));
                    }
                }
                if (status == StoreStatus.NearEviction)
                {
                    return(StoreAddResult.SuccessNearEviction);
                }
            }
            catch (OutOfMemoryException e)
            {
                Trace.error("FileSystemStorageProvider.Add()", e.ToString());
                return(StoreAddResult.NotEnoughSpace);
            }
            catch (Exception e)
            {
                Trace.error("FileSystemStorageProvider.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);
         }
         lock (_itemDict)
         {
             object obj2 = _internalStore.Add(key, item, base.CacheContext);
             if (obj2 != null)
             {
                 _itemDict.Add(key, obj2);
                 this.SetStateChanged();
                 base.Added(item as ISizable);
             }
         }
         if (status == StorageProviderBase.StoreStatus.NearEviction)
         {
             return(StoreAddResult.SuccessNearEviction);
         }
     }
     catch (OutOfMemoryException exception)
     {
         Colosoft.Logging.Trace.Error("FileSystemStorageProvider.Add()".GetFormatter(), exception.GetFormatter());
         return(StoreAddResult.NotEnoughSpace);
     }
     catch (Exception exception2)
     {
         Colosoft.Logging.Trace.Error("FileSystemStorageProvider.Add()".GetFormatter(), exception2.GetFormatter());
         return(StoreAddResult.Failure);
     }
     return(StoreAddResult.Success);
 }