public void CacheKeepsMostRecentlyUsedItems() { var cache = new MemoryCountCache <int, string>(10); for (int i = 0; i < 15; i++) { cache.AddOrUpdate(i, RandomUtils.GetInt32().ToString()); if (i == 8) { // Use first 3 items. for (int k = 0; k < 3; ++k) { cache.TryGetValue(k, out string unused); } } } // Cache should have 0-2 & 8-14. for (int i = 0; i < 15; i++) { bool success = cache.TryGetValue(i, out string unused); if (i < 3 || i > 7) { Assert.True(success); } else { Assert.False(success); } } Assert.Equal(10, cache.Count); }
public RocksDbChainStore(Network network, DataFolder dataFolder, ChainIndexer chainIndexer) { this.dataFolder = dataFolder.ChainPath; this.network = network; this.ChainIndexer = chainIndexer; this.headers = new MemoryCountCache <uint256, BlockHeader>(601); this.locker = new object(); this.dbOptions = new DbOptions().SetCreateIfMissing(true); this.rocksDb = RocksDb.Open(this.dbOptions, this.dataFolder); }
public RocksdbChainStore(Network network, DataFolder dataFolder, ChainIndexer chainIndexer) { this.network = network; this.ChainIndexer = chainIndexer; this.nearTipHeaders = new MemoryCountCache <uint256, BlockHeader>(601); this.recentHeaders = new MemoryCountCache <uint256, BlockHeader>(100); this.locker = new object(); // Open a connection to a new DB and create if not found var options = new DbOptions().SetCreateIfMissing(true); this.rocksdb = RocksDb.Open(options, dataFolder.ChainPath); }
public void CacheDoesNotExceedMaxItemsLimit() { int maxItemsCount = 100; var cache = new MemoryCountCache <int, string>(maxItemsCount); for (int i = 0; i < maxItemsCount * 2; i++) { cache.AddOrUpdate(i, RandomUtils.GetInt32().ToString()); } Assert.Equal(maxItemsCount, cache.Count); }
public LevelDbChainStore(Network network, DataFolder dataFolder, ChainIndexer chainIndexer) { this.network = network; this.ChainIndexer = chainIndexer; this.headers = new MemoryCountCache <uint256, BlockHeader>(601); this.locker = new object(); // Open a connection to a new DB and create if not found var options = new Options { CreateIfMissing = true }; this.leveldb = new DB(options, dataFolder.ChainPath); }
public void CacheKeepsMostRecentlyAddedItemsNoneWereUsed() { int maxItemsCount = 10; int itemsCountToAdd = 100; var cache = new MemoryCountCache <int, string>(maxItemsCount); for (int i = 0; i < itemsCountToAdd; i++) { cache.AddOrUpdate(i, RandomUtils.GetInt32().ToString()); } for (int i = itemsCountToAdd - maxItemsCount; i < itemsCountToAdd; i++) { bool success = cache.TryGetValue(i, out string value); Assert.True(success); } Assert.Equal(maxItemsCount, cache.Count); }
public void CanManuallyRemoveItemsFromTheCache() { var cache = new MemoryCountCache <int, string>(10); for (int i = 0; i < 5; i++) { cache.AddOrUpdate(i, i + "VALUE"); } for (int i = 0; i < 3; i++) { cache.Remove(i); } Assert.Equal(2, cache.Count); // Check if cache still has the same values that were added. for (int i = 3; i < 5; i++) { cache.TryGetValue(i, out string value); Assert.Equal(i + "VALUE", value); } }