/// <summary> /// Returns a ValueTask + uses a cache /// </summary> /// <param name="StartDate"></param> /// <returns></returns> public static ValueTask <IEnumerable <HistoricalQuote> > GetHistoricalData(DateTime StartDate) { if (HistoricalDataCache?.Last().Date < StartDate) { return(new ValueTask <IEnumerable <HistoricalQuote> >(HistoricalDataCache.Where(n => n.Date >= StartDate))); } else { var task = HistoricalPriceReader.GetNewerThan(StartDate); task.ContinueWith((n) => HistoricalDataCache = n.Result); return(new ValueTask <IEnumerable <HistoricalQuote> >(task)); } }
public async Task ShouldCache() { var sgx = new Mock <ISgxClient>(MockBehavior.Strict); sgx.SetupSequence(c => c.GetDay(It.IsAny <Day>())).ReturnsAsync("Hello!"); using (var directory = Temporary.GetEmptyDirectory()) { var cache = new HistoricalDataCache(sgx.Object, directory); Day day = 1; var data = await cache.GetDay(day); File.ReadAllText(cache.GetCacheFile(day).Absolute).Should().Be(data); } }