public async Task <int> GetNextPrimeNumberAsync(int value) { var key = $@"{value}_next"; if (cacheRepository.Has($@"{value}_next")) { return(await cacheRepository.GetAsync <int>(key)); } var nextValue = await primeNumberService.GetNextPrimeNumberAsync(value); await cacheRepository.SetAsync(key, nextValue); return(nextValue); }
public async Task <RefreshTokenModel> GetRefreshTokenAsync(string key) { var data = await _cacheRepository.GetAsync(key).ConfigureAwait(false); if (string.IsNullOrEmpty(data)) { return(null); } return(new RefreshTokenModel ( refreshToken: key, data: JsonConvert.DeserializeObject <RefreshTokenData>(data) )); }
public async Task <ActionResult <UserEntity> > Get() { var keys = await this.cacheRepository.GetKeysAsync("*user*"); if (keys.Any()) { this.cacheRepository.DeletePatternAsync("*user*"); } var entity = await cacheRepository.GetAsync("user"); if (entity == null) { var newUser = new UserEntity() { Date = DateTime.Now, GlobalId = Guid.NewGuid(), Id = ObjectId.GenerateNewId(), Name = "XXX", OtherDate = DateTimeOffset.Now }; cacheRepository.SetAsync("user", newUser); return(newUser); } else { return(entity); } }
public async Task <CreditCard> Get(string id) { var cachedCreditCard = await cacheRepository.GetAsync(id); if (cachedCreditCard == null) { var creditCard = await policy.ExecuteAsync(() => creditCardRepository.GetCreditCard(id)); await cacheRepository.SetAsync(id, creditCard); GenerateAuditEvent(id, 1, "Return credit card from database"); return(creditCard); } GenerateAuditEvent(id, 2, "Return credit card from cache"); return(cachedCreditCard as CreditCard); }
public async Task <Customer> Get(string id) { var cacheCustomer = await cacheRepository.GetAsync(id); if (cacheCustomer == null) { var customer = await customerRepository.GetCustomer(id); await policy.ExecuteAsync(() => cacheRepository.SetAsync(id, customer)); GenerateAuditEvent(id, 1, "Return customer from database"); return(customer); } GenerateAuditEvent(id, 2, "Return customer from cache"); return(cacheCustomer as Customer); }
public async Task <IList <Category> > GetAllAsync() { try { var data = await cache.GetAsync <IList <Category> >(CacheConstant.CATEGORY_KEY); if (data == null) { data = await dbRepository.GetAllAsync(); cache.SetAsync(CacheConstant.CATEGORY_KEY, data); } return(data); } catch (Exception ex) { logger.LogError(ex.StackTrace); throw new Exception($"Failed to Get All {nameof(Category)}", ex); } }
public async Task <AccountStatement> GetAsync(int accountNumber, string month) { var key = $"{accountNumber}-{month}"; if (_cacheRepository.KeyExistsAsync(key).Result) { return(await _cacheRepository.GetAsync(key)); } else { var document = await _documentRepository.GetAsync(key); if (document != null) { await _cacheRepository.SetAsync(key, document, TimeSpan.FromSeconds(_cacheExpiryInSeconds)); } return(document); } }