public async Task <SquadRepositoryDto> GetByTypeAsync(string type) { var cacheKey = GetCacheKeyFromType(type); var cached = await cache.GetAsync(cacheKey); if (cached != null) { return(BsonSerializer.Deserialize <SquadRepositoryDto>(cached)); } var stored = await Collection.Find(squad => squad.Type == type).FirstOrDefaultAsync() ?? throw EntityNotFoundException.CreateSquad(type); await cache.SetAsync(cacheKey, stored.ToBson(), cacheOptions.Value); return(stored); }