public async Task <bool> AddSessionAsync(Session value, string tokenId)
        {
            var sessionCacheKey = await GetSessionCacheKeyAsync(value.UserId, tokenId);

            if (sessionCacheKey == null)
            {
                throw new ApiError(new ServerException("INVALID SESSION CACHE KEY!!!!"));
            }

            var session = await sessionProvider.GetModelBySearchPredicate(x => x.UserId == value.UserId &&
                                                                          x.SessionId == sessionCacheKey.SessionId);

            if (session == null)
            {
                throw new ApiError(new ServerException("Invalid sessions!!!"));
            }

            string cacheKey = CacheKeyFactories.GenerateSessionCacheKey(value.UserId, tokenId, EntityKey);

            var cacheModel = new SessionCacheModel()
            {
                ClientPublicKey  = session.ClientPublicKey,
                ServerPrivateKey = session.ServerPrivateKey,
                ServerPublicKey  = session.ServerPublicKey,
                UserId           = session.UserId,
                SessionId        = session.SessionId
            };

            string json = JsonConvert.SerializeObject(cacheModel);
            await cacheDb.StringSetAsync(cacheKey, json);

            return(true);
        }
        public async Task <SessionCacheModel> GetSessionsFromCacheAsync(string userId, string tokenId)
        {
            var sessionCacheKey = await GetSessionCacheKeyAsync(userId, tokenId);

            if (sessionCacheKey == null)
            {
                throw new ApiError(new ServerException("Invalid session cache key!!!"));
            }

            string cacheKey = CacheKeyFactories.GenerateSessionCacheKey(userId, tokenId, EntityKey);

            var dataFromCache = await cacheDb.StringGetAsync(new RedisKey(cacheKey));

            if (dataFromCache.HasValue)
            {
                var result = JsonConvert.DeserializeObject <SessionCacheModel>(dataFromCache);
                return(result);
            }

            var sessionFromDb = await sessionProvider.GetModelBySearchPredicate(x => x.UserId == userId && x.SessionId == sessionCacheKey.SessionId);

            if (sessionFromDb == null)
            {
                return(null);
            }

            await CacheSetString(cacheKey, sessionFromDb, TimeSpan.FromMinutes(authOptions.Value.AccessTokenLifeTime));

            return(new SessionCacheModel()
            {
                ClientPublicKey = sessionFromDb.ClientPublicKey,
                ServerPrivateKey = sessionFromDb.ServerPrivateKey,
                ServerPublicKey = sessionFromDb.ServerPublicKey,
                SessionId = sessionFromDb.SessionId,
                UserId = sessionFromDb.UserId
            });
        }