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