コード例 #1
0
ファイル: CachingService.cs プロジェクト: TheDarkCode/BusVbot
        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);
        }
コード例 #2
0
        private CacheUserContext2 GetOrCreateCacheEntryFor(UserChat userChat)
        {
            if (!_cache.TryGetValue(userChat, out CacheUserContext2 cacheContext))
            {
                cacheContext = new CacheUserContext2();
                _cache.Set(userChat, cacheContext);
            }

            return(cacheContext);
        }