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) ); }
public async Task <DataTablesResponse> GetUserOrders(DataTablesModel param, string userId) { var cacheResult = await CacheService.GetOrSetHybridAsync(CacheKey.ExchangeUserOpenOrderDataTable(userId), TimeSpan.FromMinutes(60), async() => { using (var context = ExchangeDataContextFactory.CreateReadOnlyContext()) { var currentUser = new Guid(userId); var open = await context.Trade .AsNoTracking() .Where(x => x.UserId == currentUser && (x.Status == TradeStatus.Partial || x.Status == TradeStatus.Pending)) .OrderByDescending(x => x.Id) .Select(x => new { Timestamp = x.Timestamp, Type = x.Type, Rate = x.Rate, Amount = x.Amount, Remaining = x.Remaining, TradeId = x.Id, TradePairId = x.TradePairId, Symbol1 = x.TradePair.Currency1.Symbol, Symbol2 = x.TradePair.Currency2.Symbol }).ToListNoLockAsync().ConfigureAwait(false); var orderData = open.Select(x => new { Market = string.Format("{0}/{1}", x.Symbol1, x.Symbol2), Type = x.Type.ToString(), Rate = x.Rate.ToString("F8"), Remaining = x.Remaining.ToString("F8"), TradeId = x.TradeId.ToString(), TradePairId = x.TradePairId.ToString() }).GetDataTableResult(param, true); return(orderData); } }).ConfigureAwait(false); return(cacheResult); }