예제 #1
0
        public override void Dispose()
        {
            try
            {
                if (!_disposed)
                {
                    _chainDb?.Dispose();
                    _txIndexDb?.Dispose();
                    _blockIndexDb?.Dispose();
                    _blockPerceptionDb?.Dispose();
                    _stagedTxDb?.Dispose();
                    _txExecutionDb?.Dispose();
                    _txIdBlockHashIndexDb?.Dispose();
                    foreach (var db in _txDbCache.Values)
                    {
                        db.Dispose();
                    }

                    _txDbCache.Clear();

                    foreach (var db in _blockDbCache.Values)
                    {
                        db.Dispose();
                    }

                    _blockDbCache.Clear();
                    _disposed = true;
                }
            }
            catch (Exception e)
            {
                LogUnexpectedException(nameof(Dispose), e);
            }
        }
예제 #2
0
 public void Clear()
 {
     foreach (T obj in cache)
     {
         OnPushedOutFromCache(obj);
     }
     cache.Clear();
 }
예제 #3
0
 public void LruCache_Clear()
 {
     LruCache<int, string> cache = new LruCache<int, string>(2);
     cache.Put(1, "One");
     cache.Put(2, "Two");
     Assert.AreEqual(2, cache.Count);
     cache.Clear();
     Assert.AreEqual(0, cache.Count);
 }
        public void WithClear()
        {
            for (int j = 0; j < 1024 * 64; j++)
            {
                shared.Set(j, _object);
            }

            shared.Clear();
        }
예제 #5
0
        /// <summary>
        /// Clear all actors from the system.  Each active actor will be deactivated
        /// </summary>
        /// <param name="context">context</param>
        /// <returns></returns>
        public IReadOnlyList <ActorInstance> Clear()
        {
            _logger.LogTrace($"{nameof(Clear)}: Clearing actor container");
            List <ActorInstance> list;

            lock (_lock)
            {
                list = new List <ActorInstance>(_actorCache.GetValues());
                _actorCache.Clear();
                return(list);
            }
        }
예제 #6
0
        public void Cache_should_be_clear_on_demand()
        {
            ICache cache = new LruCache();

            for (int i = 0; i < 5; i++)
            {
                cache[i] = i;
            }

            Assert.That(cache[0], Is.Not.Null);
            Assert.That(cache[4], Is.Not.Null);
            cache.Clear();
            Assert.That(cache[0], Is.Null);
            Assert.That(cache[4], Is.Null);
        }
예제 #7
0
        public void LruCache_Clear_EmptiesCollection()
        {
            const int expectedCount = 50;

            var cache = new LruCache <string, string>(100);

            foreach (var value in Enumerable.Range(0, expectedCount).Select(v => v.ToString()))
            {
                cache.Add(value, value);
            }
            Assert.Equal(expectedCount, cache.Count);

            cache.Clear();

            Assert.Equal(0, cache.Count);
        }
예제 #8
0
        public void EnumeratorChangedClear()
        {
            var cache = new LruCache <int, int>(10);

            for (int index = 0; index < 10; ++index)
            {
                cache.Add(index, index);
            }

            var  enumerator = cache.GetEnumerator();
            bool success    = enumerator.MoveNext();

            Assert.IsTrue(success, "Enumerator should move");

            cache.Clear();

            CheckForInvalidEnumerator(enumerator);
        }
예제 #9
0
        public override void Dispose()
        {
            _chainDb?.Dispose();
            _txIndexDb?.Dispose();
            _blockIndexDb?.Dispose();
            _blockPerceptionDb?.Dispose();
            _stagedTxDb?.Dispose();
            foreach (var db in _txDbCache.Values)
            {
                db.Dispose();
            }

            _txDbCache.Clear();

            foreach (var db in _blockDbCache.Values)
            {
                db.Dispose();
            }

            _blockDbCache.Clear();
        }
예제 #10
0
        public void AddRemoveTest()
        {
            var cache = new LruCache <string, TestClass, TestClass>(
                100,
                value => value.Text);

            TestClass item = new TestClass("1");

            cache.Add(item);
            Assert.AreEqual(1, cache.Count);
            item = new TestClass("2");
            cache.Add(item);
            Assert.AreEqual(2, cache.Count);
            Assert.AreEqual(item, cache[item.Text, false]);
            ICache <string, TestClass> icache = cache;

            Assert.AreEqual(item, icache[item.Text, false]);
            Assert.AreEqual(null, icache["3", false]);
            cache.Remove(item);
            Assert.AreEqual(1, cache.Count);
            cache.Clear();
            Assert.AreEqual(0, cache.Count);
        }
예제 #11
0
        public void ClearItems()
        {
            var cache = new LruCache <string, TestData>(10);

            for (int index = 0; index < 10; ++index)
            {
                cache.AddOrUpdate(index.ToString(), new TestData());
            }

            Assert.AreEqual(10, cache.Count, "Cache size incorrect before clearing");
            for (int index = 0; index < 10; ++index)
            {
                var item = cache.Get(index.ToString());
                Assert.IsNotNull(item, "Removed item should exist in cache");
            }

            cache.Clear();
            Assert.AreEqual(0, cache.Count, "Cache size incorrect after clearing");
            for (int index = 0; index < 10; ++index)
            {
                bool removed = cache.Remove(index.ToString());
                Assert.IsFalse(removed, "Removed item shouldn't exist in cache");
            }
        }
예제 #12
0
 public void Clear()
 {
     _cache.Clear();
 }
예제 #13
0
 public override void Clear()
 {
     LruCache.Clear();
 }
예제 #14
0
        public void Clear_CacheIsNotEmpty_CurrentSizeIsZero()
        {
            var lru = new LruCache<string, string>(5);
            lru.Add("k1", "v1");
            lru.Add("k2", "v2");
            lru.Add("k3", "v3");
            lru.Add("k4", "v4");
            lru.Add("k5", "v5");

            Assert.AreEqual(5, lru.CurrentSize);

            lru.Clear();

            Assert.AreEqual(0, lru.CurrentSize);
        }
 public void Clear() => _cache.Clear();
예제 #16
0
 private void ClearAllCaches()
 {
     InvalidateClientBuffer();
     dbIdCache.Clear();
     clientDbNames.Clear();
 }
예제 #17
0
 public void LruCache_MakeSureItemRemovedEventIsCalledWhenClearingList()
 {
     LruCache<int, string> cache = new LruCache<int, string>(2);
     List<string> removedList = new List<string>();
     cache.ItemRemoved += (o, s) => { removedList.Add(s.Item); };
     cache.Put(1, "One");
     cache.Put(2, "Two");
     Assert.AreEqual(0, removedList.Count);
     cache.Clear();
     Assert.AreEqual(2, removedList.Count);
     Assert.AreEqual("One", removedList[0]);
     Assert.AreEqual("Two", removedList[1]);
 }