public BoundedFullCache(string name, IBoundedStorage <TKey, TValue> dataStorage, Logger logger) { this.logger = logger; this.name = name; this.dataStorage = dataStorage; this.missingData = new ConcurrentSetBuilder <TKey>(); // load from storage this.cache = new ConcurrentDictionary <TKey, TValue>(this.dataStorage); this.logger.Info("{0}: Finished loading from storage: {1:#,##0}".Format2(this.Name, this.Count)); }
public BoundedCache(string name, IBoundedStorage <TKey, TValue> dataStorage, Logger logger) { this.logger = logger; this.name = name; this.dataStorage = dataStorage; this.knownKeys = new ConcurrentSet <TKey>(); this.missingData = new ConcurrentSetBuilder <TKey>(); // load existing keys from storage this.knownKeys.UnionWith(this.dataStorage.Keys); this.logger.Info("{0}: Finished loading from storage: {1:#,##0}".Format2(this.Name, this.Count)); }
public BoundedCache(string name, IBoundedStorage <TKey, TValue> dataStorage, long maxFlushMemorySize, long maxCacheMemorySize, Func <TValue, long> sizeEstimator) : base(name, dataStorage, maxFlushMemorySize, maxCacheMemorySize, sizeEstimator) { this.knownKeysLock = new ReaderWriterLockSlim(); this.knownKeys = new ConcurrentSet <TKey>(); this._dataStorage = dataStorage; this.OnAddition += key => AddKnownKey(key); this.OnModification += (key, value) => AddKnownKey(key); this.OnRetrieved += (key, value) => AddKnownKey(key); this.OnMissing += key => RemoveKnownKey(key); // load existing keys from storage LoadKeyFromStorage(); }
public LocalClient(LocalClientType type, BlockchainDaemon blockchainDaemon, IBoundedStorage<NetworkAddressKey, NetworkAddressWithTime> knownAddressStorage) { this._type = type; this.blockchainDaemon = blockchainDaemon; this.shutdownToken = new CancellationTokenSource(); this.knownAddressCache = new BoundedCache<NetworkAddressKey, NetworkAddressWithTime> ( "KnownAddressCache", dataStorage: knownAddressStorage, maxFlushMemorySize: 5.THOUSAND(), maxCacheMemorySize: 500.THOUSAND(), sizeEstimator: knownAddress => 40 ); this.connectWorker = new Worker("LocalClient.ConnectWorker", ConnectWorker, true, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); this.requestBlocksWorker = new Worker("LocalClient.RequestBlocksWorker", RequestBlocksWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000)); this.requestHeadersWorker = new Worker("LocalClient.RequestHeadersWorker", RequestHeadersWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000)); this.statsWorker = new Worker("LocalClient.StatsWorker", StatsWorker, true, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30)); this.blockchainDaemon.OnWinningBlockChanged += OnWinningBlockChanged; switch (this.Type) { case LocalClientType.MainNet: Messaging.Port = 8333; Messaging.Magic = Messaging.MAGIC_MAIN; break; case LocalClientType.TestNet3: Messaging.Port = 18333; Messaging.Magic = Messaging.MAGIC_TESTNET3; break; case LocalClientType.ComparisonToolTestNet: Messaging.Port = 18444; Messaging.Magic = Messaging.MAGIC_COMPARISON_TOOL; break; } }
public LocalClient(LocalClientType type, BlockchainDaemon blockchainDaemon, IBoundedStorage <NetworkAddressKey, NetworkAddressWithTime> knownAddressStorage) { this._type = type; this.blockchainDaemon = blockchainDaemon; this.shutdownToken = new CancellationTokenSource(); this.knownAddressCache = new BoundedCache <NetworkAddressKey, NetworkAddressWithTime> ( "KnownAddressCache", dataStorage: knownAddressStorage, maxFlushMemorySize: 5.THOUSAND(), maxCacheMemorySize: 500.THOUSAND(), sizeEstimator: knownAddress => 40 ); this.connectWorker = new Worker("LocalClient.ConnectWorker", ConnectWorker, true, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); this.requestBlocksWorker = new Worker("LocalClient.RequestBlocksWorker", RequestBlocksWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000)); this.requestHeadersWorker = new Worker("LocalClient.RequestHeadersWorker", RequestHeadersWorker, true, TimeSpan.FromMilliseconds(200), TimeSpan.FromMilliseconds(5000)); this.statsWorker = new Worker("LocalClient.StatsWorker", StatsWorker, true, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30)); this.blockchainDaemon.OnWinningBlockChanged += OnWinningBlockChanged; switch (this.Type) { case LocalClientType.MainNet: Messaging.Port = 8333; Messaging.Magic = Messaging.MAGIC_MAIN; break; case LocalClientType.TestNet3: Messaging.Port = 18333; Messaging.Magic = Messaging.MAGIC_TESTNET3; break; case LocalClientType.ComparisonToolTestNet: Messaging.Port = 18444; Messaging.Magic = Messaging.MAGIC_COMPARISON_TOOL; break; } }