public BlockStoreCache(
            IBlockRepository blockRepository,
            IDateTimeProvider dateTimeProvider,
            ILoggerFactory loggerFactory,
            NodeSettings nodeSettings,
            IMemoryCache memoryCache = null)
        {
            Guard.NotNull(blockRepository, nameof(blockRepository));

            // Initialize 'MaxCacheBlocksCount' with default value of maximum 300 blocks or with user defined value.
            // Value of 300 is chosen because it covers most of the cases when not synced node is connected and trying to sync from us.
            this.MaxCacheBlocksCount = nodeSettings.ConfigReader.GetOrDefault("maxCacheBlocksCount", 300);

            this.cache = memoryCache;
            if (this.cache == null)
            {
                var memoryCacheOptions = new MemoryCacheOptions()
                {
                    SizeLimit            = this.MaxCacheBlocksCount,
                    CompactionPercentage = this.CompactionPercentage
                };

                this.cache = new MemoryCache(memoryCacheOptions);
            }

            this.blockEntryOptions = new MemoryCacheEntryOptions()
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(24), Size = 1
            };

            this.blockRepository    = blockRepository;
            this.dateTimeProvider   = dateTimeProvider;
            this.PerformanceCounter = this.BlockStoreCachePerformanceCounterFactory();
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
        }
Exemple #2
0
        public BlockStoreCache(IBlockRepository blockRepository, IMemoryCache memoryCache)
        {
            Guard.NotNull(blockRepository, nameof(blockRepository));
            Guard.NotNull(memoryCache, nameof(memoryCache));

            this.blockRepository    = blockRepository;
            this.cache              = memoryCache;
            this.PerformanceCounter = BlockStoreCachePerformanceCounterFactory();
        }
        public BlockStoreCache(IBlockRepository blockRepository, IMemoryCache memoryCache, ILoggerFactory loggerFactory)
        {
            Guard.NotNull(blockRepository, nameof(blockRepository));
            Guard.NotNull(memoryCache, nameof(memoryCache));

            this.blockRepository    = blockRepository;
            this.cache              = memoryCache;
            this.PerformanceCounter = BlockStoreCachePerformanceCounterFactory();
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
        }
        public BlockStoreCache(
            IBlockRepository blockRepository,
            IDateTimeProvider dateTimeProvider,
            ILoggerFactory loggerFactory,
            StoreSettings storeSettings)
        {
            Guard.NotNull(blockRepository, nameof(blockRepository));

            this.cache              = new MemoryCache <uint256, Block>(storeSettings.MaxCacheBlocksCount);
            this.blockRepository    = blockRepository;
            this.dateTimeProvider   = dateTimeProvider;
            this.PerformanceCounter = this.BlockStoreCachePerformanceCounterFactory();
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
        }
Exemple #5
0
        public BlockStoreCache(
            IBlockRepository blockRepository,
            IDateTimeProvider dateTimeProvider,
            ILoggerFactory loggerFactory,
            NodeSettings nodeSettings)
        {
            Guard.NotNull(blockRepository, nameof(blockRepository));

            // Initialize 'MaxCacheBlocksCount' with default value of maximum 300 blocks or with user defined value.
            // Value of 300 is chosen because it covers most of the cases when not synced node is connected and trying to sync from us.
            this.MaxCacheBlocksCount = nodeSettings.ConfigReader.GetOrDefault("maxCacheBlocksCount", 300);

            this.cache = new MemoryCache <uint256, Block>(this.MaxCacheBlocksCount);

            this.blockRepository    = blockRepository;
            this.dateTimeProvider   = dateTimeProvider;
            this.PerformanceCounter = this.BlockStoreCachePerformanceCounterFactory();
            this.logger             = loggerFactory.CreateLogger(this.GetType().FullName);
        }