public async Task <ArmorRepositoryDto> GetByNameAsync(string name) { var cacheKey = GetCacheKeyFromName(name); var cached = await cache.GetAsync(cacheKey); if (cached != null) { return(BsonSerializer.Deserialize <ArmorRepositoryDto>(cached)); } var stored = await Collection.Find(armor => armor.Name == name).FirstOrDefaultAsync() ?? throw EntityNotFoundException.CreateArmor(name); await cache.SetAsync(cacheKey, stored.ToBson(), cacheOptions.Value); return(stored); }