Ejemplo n.º 1
0
        public CacheItem <V> Remove(K key)
        {
            CacheItem <V> i = new CacheItem <V>();

            if (_cacheDic.ContainsKey(key) && (_timerDic.ContainsKey(key)))
            {
                var cacheTimer = _timerDic[key];
                _cacheDic.TryRemove(key, out i);
                cacheTimer.Elapsed  -= new ElapsedEventHandler(Elapsed_Event);
                cacheTimer.Enabled   = false;
                cacheTimer.AutoReset = false;
                cacheTimer.Stop();
                cacheTimer.Close();
                cacheTimer.Dispose();
                if (DormantCacheCount == 0 && ActiveCount == 0)
                {
                    EmptyCacheEvent?.Invoke(this, new EventArgs());
                }
            }
            else
            {
                var dic = ReadBinary();
                if (dic.ContainsKey(key))
                {
                    if (dic.TryRemove(key, out i))
                    {
                        WriteBinary(dic);
                    }
                }
            }
            return(i);
        }
Ejemplo n.º 2
0
 public void Clear()
 {
     _cacheDic.Clear();
     _timerDic.Clear();
     _cleaner.Stop();
     _cleaner.Start();
     WriteCache();
     EmptyCacheEvent?.Invoke(this, new EventArgs());
 }
Ejemplo n.º 3
0
 private void Cleaner_Event(object sender, ElapsedEventArgs e)
 {
     System.Threading.Thread cleaner = new System.Threading.Thread(() =>
     {
         var dic = ReadBinary();
         WriteBinary(dic);
         if (_dormantCacheCount == 0 && ActiveCount == 0)
         {
             EmptyCacheEvent?.Invoke(this, new EventArgs());
         }
     });
     cleaner.Start();
 }