ToCacheKey() public method

public ToCacheKey ( ) : string
return string
        /// <summary>
        /// Updates the UserSession in the cache, or removes expired ones.
        /// </summary>
        /// <param name="userSession">The user session.</param>
        public void UpdateUserSession(UserSession userSession)
        {
            var hasSessionExpired = userSession.HasExpired();

            if (hasSessionExpired)
            {
                LogIfDebug("Session has expired, removing: " + userSession.ToCacheKey());
                this.cacheClient.Remove(userSession.ToCacheKey());
            }
            else
            {
                LogIfDebug("Updating session: " + userSession.ToCacheKey());
                this.cacheClient.Replace(userSession.ToCacheKey(), userSession, userSession.ExpiryDate.Value);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the user session if it exists or null.
        /// </summary>
        /// <param name="userId">The user global id.</param>
        /// <returns></returns>
        public async ValueTask <UserSessionAsync> GetUserSessionAsync(Guid userId)
        {
            var cacheKey = UserSession.ToCacheKey(userId);
            var bytes    = await this.cacheClient.GetAsync <byte[]>(cacheKey);

            if (bytes != null)
            {
                var modelStr = Encoding.UTF8.GetString(bytes);
                LogIfDebug("UserSession => " + modelStr);
            }
            return(await this.cacheClient.GetAsync <UserSessionAsync>(cacheKey));
        }
        /// <summary>
        /// Gets the user session if it exists or null.
        /// </summary>
        /// <param name="userId">The user global id.</param>
        /// <returns></returns>
        public UserSession GetUserSession(Guid userId)
        {
            var cacheKey = UserSession.ToCacheKey(userId);
            var bytes    = this.cacheClient.Get <byte[]>(cacheKey);

            if (bytes != null)
            {
                var modelStr = Encoding.UTF8.GetString(bytes);
                LogIfDebug("UserSession => " + modelStr);
            }
            return(this.cacheClient.Get <UserSession>(cacheKey));
        }
        /// <summary>
        /// Gets or create a user session if one doesn't exist.
        /// </summary>
        /// <param name="userId">The user global id.</param>
        /// <param name="userName">Title of the user.</param>
        /// <param name="shardId"></param>
        /// <returns></returns>
        public UserSession GetOrCreateSession(Guid userId, string userName, string shardId)
        {
            var userSession = this.GetUserSession(userId);

            if (userSession == null)
            {
                userSession = new UserSession(userId, userName, shardId);

                this.cacheClient.Add(userSession.ToCacheKey(), userSession,
                                     userSession.ExpiryDate.GetValueOrDefault(DateTime.UtcNow) + TimeSpan.FromHours(1));
            }
            return(userSession);
        }
		/// <summary>
		/// Gets or create a user session if one doesn't exist.
		/// </summary>
		/// <param name="userId">The user global id.</param>
		/// <param name="userName">Title of the user.</param>
		/// <param name="shardId"></param>
		/// <returns></returns>
		public UserSession GetOrCreateSession(Guid userId, string userName, string shardId)
		{
			var userSession = this.GetUserSession(userId);
			if (userSession == null)
			{
				userSession = new UserSession(userId, userName, shardId);

				this.cacheClient.Add(userSession.ToCacheKey(), userSession,
					userSession.ExpiryDate.GetValueOrDefault(DateTime.UtcNow) + TimeSpan.FromHours(1));
			}
			return userSession;
		}
		/// <summary>
		/// Updates the UserSession in the cache, or removes expired ones.
		/// </summary>
		/// <param name="userSession">The user session.</param>
		public void UpdateUserSession(UserSession userSession)
		{
			var hasSessionExpired = userSession.HasExpired();
			if (hasSessionExpired)
			{
				LogIfDebug("Session has expired, removing: " + userSession.ToCacheKey());
				this.cacheClient.Remove(userSession.ToCacheKey());
			}
			else
			{
				LogIfDebug("Updating session: " + userSession.ToCacheKey());
				this.cacheClient.Replace(userSession.ToCacheKey(), userSession, userSession.ExpiryDate.Value);
			}
		}