Exemplo n.º 1
0
        public async Task <int> GetTotalDonationsAmount()
        {
            var cachedValue = await _cacheService.Get <int>(TotalAmountKey);

            if (cachedValue.Exists)
            {
                return(cachedValue.Value);
            }
            else
            {
                var donations = await _repository.GetAllDonations();

                var total = (int)donations.Sum(d => d.Amount);
                await _cacheService.Set(TotalAmountKey, total, TimeSpan.FromSeconds(30));

                return(total);
            }
        }