Exemplo n.º 1
0
 /// <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>
 /// Carrega o estado.
 /// </summary>
 void IPersistentCacheStorage.LoadStorageState()
 {
     try
     {
         string path = Path.Combine(_internalStore.RootDir, "__ncfs__.state");
         lock (_itemDict)
         {
             using (Stream stream = new FileStream(path, FileMode.Open))
             {
                 using (BinaryReader reader = new BinaryReader(stream))
                 {
                     int num = reader.ReadInt32();
                     _itemDict.Clear();
                     if (num >= 1)
                     {
                         for (int i = 0; i < num; i++)
                         {
                             int count = reader.ReadInt32();
                             if (count >= 0)
                             {
                                 try
                                 {
                                     StoreItem item = StoreItem.FromBinary(reader.ReadBytes(count), base.CacheContext);
                                     if (_internalStore.Contains(item.Value))
                                     {
                                         _itemDict.Add(item.Key, item.Value);
                                     }
                                 }
                                 catch (Exception)
                                 {
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Colosoft.Logging.Trace.Error("FileSystemStorageProvider.LoadStorageState()".GetFormatter(), exception.GetFormatter());
     }
     finally
     {
         this.ResetStateChanged();
     }
 }
Exemplo n.º 3
0
 /// <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);
 }
Exemplo n.º 4
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());
     }
 }