public async Task <DateTime?> Handle(TrainTimesLastImportQuery request, CancellationToken cancellationToken) { var lastImportDate = await _memoryCache.GetOrCreateAsync(CacheKeyHelper.GetLastImportDateCacheKey(), async entry => { entry.AbsoluteExpiration = DateTime.Now.EndOfDay(); var earliestImportLog = await _peatusContext.ImportLogs.OrderByDescending(x => x.ImportDate) .FirstOrDefaultAsync(cancellationToken); return(earliestImportLog?.ImportDate); }); return(lastImportDate); }