public async Task <List <string[]> > GetUserHistory(string userId, int tradePairId) { var cacheResult = await CacheService.GetOrSetHybridAsync(CacheKey.ExchangeUserTradeHistory(userId, tradePairId), TimeSpan.FromMinutes(60), async() => { using (var context = ExchangeDataContextFactory.CreateReadOnlyContext()) { var currentUser = new Guid(userId); var history = await context.TradeHistory .AsNoTracking() .Where(x => (x.UserId == currentUser || x.ToUserId == currentUser) && x.TradePairId == tradePairId) .OrderByDescending(x => x.Id) .Take(100) .Select(x => new { Timestamp = x.Timestamp, Type = x.ToUserId == currentUser ? TradeHistoryType.Sell : TradeHistoryType.Buy, Rate = x.Rate, Amount = x.Amount, }).ToListNoLockAsync().ConfigureAwait(false); var historydata = history.Select(x => new[] { x.Timestamp.ToString(), x.Type.ToString(), x.Rate.ToString("F8"), x.Amount.ToString("F8"), (x.Amount *x.Rate).ToString("F8") }); return(historydata.ToList()); } }).ConfigureAwait(false); return(cacheResult); }
private async Task ClearCache(int tradePairId, Guid userId) { await CacheService.InvalidateAsync ( CacheKey.ExchangeUserOpenOrders(userId.ToString(), tradePairId), CacheKey.ExchangeUserTradeHistory(userId.ToString(), tradePairId), CacheKey.ExchangeUserOpenOrderDataTable(userId.ToString()), CacheKey.ExchangeUserOrderBook(userId.ToString(), tradePairId) ); }