public Position GetNewestByImei(string imei) { var cachedPosition = _positions.GetAll(imei)?.OrderByDescending(x => x.Date).FirstOrDefault() ?? null; if (cachedPosition is null) { using (var scope = _scopeFactory.CreateScope()) { var db = GetContext(scope); return(db.Positions.Where(x => x.Imei == imei).OrderByDescending(x => x.Date).FirstOrDefault()); } } return(cachedPosition); }