public virtual async Task <List <T> > GetAllAsync(bool skipDatabaseConsistencyCheck = false) { // If this is the first time the GetAllAsync has been called, we return 0, despite the fact that there might be some in the cache. // This is because we want to force the call to the database to ensure that we have a true "all" which will also then populate the cache. if (skipDatabaseConsistencyCheck) { var allItemsNonDbCheck = await _appCache.GetAllItemsInPartitionAsync <T>(PartitionNameFormatter()).ConfigureAwait(false); return(allItemsNonDbCheck); } var lastCallToGetAllKey = ComposeLastCallToGetAllCacheKey(); var containsKey = await _appCache.ContainsAsync(lastCallToGetAllKey).ConfigureAwait(false); if (containsKey) { await _appCache.AddOrUpdateAsync(lastCallToGetAllKey, DateTimeOffset.UtcNow, TimeSpan.FromDays(2)).ConfigureAwait(false); var response = await _appCache.GetAllItemsInPartitionAsync <T>(PartitionNameFormatter()).ConfigureAwait(false); return(response); } await _appCache.AddOrUpdateAsync(lastCallToGetAllKey, DateTimeOffset.UtcNow, TimeSpan.FromDays(2)).ConfigureAwait(false); return(new List <T>()); }
public async Task <List <Minion> > GetAllMinionsAsync() { _allMinions = await _appCache.GetAllItemsInPartitionAsync <Minion>(typeof(Minion).Name).ConfigureAwait(false); if (_allMinions != null && _allMinions.Count > 0) { return(_allMinions.OrderBy(m => m.Name).ToList()); } _allMinions = await GenerateMinionsAsync().ConfigureAwait(false); return(_allMinions.OrderBy(m => m.Name).ToList()); }
public void ShouldSaveItemsIntoPartition() { // Arrange foreach (var userInfo in _users) { _appCache.AddOrUpdateAsync(userInfo.EntityId.ToString(), userInfo, null, "Users").WaitAndUnwrapException(); } // Act var user1 = _appCache.GetValueAsync <UserInfo>(_users[0].EntityId.ToString(), "Users").WaitAndUnwrapException(); var allUsers = _appCache.GetAllItemsInPartitionAsync <UserInfo>("Users").WaitAndUnwrapException(); // Assert Assert.IsNotNull(user1); Assert.AreEqual(user1.EntityId, _users[0].EntityId); Assert.AreEqual(allUsers.Count, _users.Count); }