public async Task <CacheUserContext2> GetCachedContextAsync(UserChat userchat) { CacheUserContext2 cacheContext2 = this[userchat]; cacheContext2 = cacheContext2 ?? new CacheUserContext2(); if (cacheContext2.AgencyTag == null) { var result = await _dbContext.UserChatContexts .Where(uc => uc.ChatId == userchat.ChatId && uc.UserId == userchat.UserId) .Select(uc => new { uc.AgencyId, uc.Agency.Tag, }) .SingleAsync(); cacheContext2.AgencyTag = result.Tag; cacheContext2.AgencyId = result.AgencyId; this[userchat] = cacheContext2; } return(cacheContext2); }
private CacheUserContext2 GetOrCreateCacheEntryFor(UserChat userChat) { if (!_cache.TryGetValue(userChat, out CacheUserContext2 cacheContext)) { cacheContext = new CacheUserContext2(); _cache.Set(userChat, cacheContext); } return(cacheContext); }