Пример #1
0
 /// <summary>
 /// Carrega o estado do armazenamento.
 /// </summary>
 void IPersistentCacheStorage.LoadStorageState()
 {
     try
     {
         lock (_itemDict.SyncRoot)
         {
             _itemDict.Clear();
             IEnumerator enumerator = _internalStore.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 MemArea current = (MemArea)enumerator.Current;
                 if (!current.IsFree)
                 {
                     StoreItem item = StoreItem.FromBinary(current.GetMemContents(), base.CacheContext);
                     _itemDict.Add(item.Key, new MmfObjectPtr(current.View, current));
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Trace.Error("MmfStorageProvider.IPersistentCacheStorage()".GetFormatter(), exception.GetFormatter());
     }
 }
Пример #2
0
        /// <summary>
        /// Salva a chave o valor informados em um buffer.
        /// </summary>
        /// <param name="key">Chave do item.</param>
        /// <param name="val">Valor do item.</param>
        /// <param name="cacheContext"></param>
        /// <returns></returns>
        public static byte[] ToBinary(object key, object val, string cacheContext)
        {
            StoreItem graph = new StoreItem(key, val);

            return(CompactBinaryFormatter.ToByteBuffer(graph, cacheContext));
        }
Пример #3
0
        /// <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);
        }