Esempio n. 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);
            }
        }
Esempio n. 2
0
 public void Clear()
 {
     foreach (T obj in cache)
     {
         OnPushedOutFromCache(obj);
     }
     cache.Clear();
 }
 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();
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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();
        }
Esempio n. 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);
        }
Esempio n. 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");
            }
        }
 public void Clear()
 {
     _cache.Clear();
 }
Esempio n. 13
0
 public override void Clear()
 {
     LruCache.Clear();
 }
Esempio n. 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();
Esempio n. 16
0
 private void ClearAllCaches()
 {
     InvalidateClientBuffer();
     dbIdCache.Clear();
     clientDbNames.Clear();
 }
 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]);
 }