public IActionResult Get(string identifier) { // This has implemented fairly basic caching of data for a minute. // In a production environment you may want to look at sql dependency injection to flush the cache only // if the underlying database values have changed. OMSTradeData cacheEntry = null; if (identifier != null && !_cache.TryGetValue(identifier.ToUpper(), out cacheEntry)) { var data = new TradeContext(); cacheEntry = data.TradeData.FirstOrDefault(t => t.Identifier == identifier); MemoryCacheEntryOptions options = new MemoryCacheEntryOptions(); options.AbsoluteExpiration = DateTime.Now.AddMinutes(1); options.SlidingExpiration = TimeSpan.FromMinutes(1); _cache.Set(cacheEntry.Identifier, cacheEntry, options); } return(Json(cacheEntry)); }
public bool CommitTrade(OMSTradeData trade) { TradeData.Add(trade); SaveChanges(); return(true); }