Exemple #1
0
        public async Task <List <CachedAccountViolations> > GetCachedAccountViolations(Guid accountId)
        {
            //First we need to get the correct cache key
            var cacheKey = WebCacheKey.AccountViolations(accountId);

            //Then we need to set the cache expiration time.
            var expiry = TimeSpan.FromMinutes(15);

            var cachedViolations = await _cache.GetWithSlidingExpirationAsync <List <CachedAccountViolations> >(cacheKey, expiry);

            if (cachedViolations == null)
            {
                var violations = await _accountCtx.Violations.ForAccount(accountId)
                                 .Include(m => m.Category).ThenInclude(m => m.Type)
                                 .ToListAsync();

                cachedViolations = Mapper.Map <List <CachedAccountViolations> >(violations);

                // Found it. Add it to the cache.
                await _cache.SetAsync(cacheKey, cachedViolations, expiry);
            }

            return(cachedViolations);
        }
Exemple #2
0
 protected async Task PurgeAccountViolation(Guid accountId)
 {
     var cacheKey = WebCacheKey.AccountViolations(accountId);
     await _cache.RemoveAsync(cacheKey);
 }