private async Task TruncateCacheAsync() { // Shall not truncate cache while reloading data. if (_cacheInitalizationService.InitializationState != CacheInitializationState.Idle) { return; } SlotType activeSlot = await _redisCacheService.GetActiveSlotAsync(_marketType); var tasks = new List <Task>(); foreach (var assetId in _historyRepository.GetStoredAssetPairs()) { foreach (var priceType in Constants.StoredPriceTypes) { foreach (var timeInterval in Constants.InitFromDbIntervals) { int candlesAmount = _amountOfCandlesToStore[timeInterval]; var intervals = _redisCacheService.GetRedisCacheIntervals(timeInterval); foreach (var interval in intervals) { tasks.Add(_redisCacheService.TruncateCacheAsync(assetId, priceType, interval, GetIntervalCandlesAmount(candlesAmount, interval), activeSlot)); } } } } await Task.WhenAll(tasks); }
public override Task Execute() { foreach (var assetId in _historyRepository.GetStoredAssetPairs()) { foreach (var priceType in Constants.StoredPriceTypes) { foreach (var timeInterval in Constants.StoredIntervals) { var key = RedisCandlesCacheService.GetKey(_market, assetId, priceType, timeInterval); _database.SortedSetRemoveRangeByRank(key, 0, -_amountOfCandlesToStore - 1, CommandFlags.FireAndForget); } } } return(Task.CompletedTask); }