Load() public static méthode

Loads a session state item from the bucket
public static Load ( IBucket bucket, string id, bool metaOnly ) : SessionStateItem
bucket IBucket Couchbase bucket to load from
id string Session ID
metaOnly bool True to load only meta data
Résultat SessionStateItem
Exemple #1
0
        /// <summary>
        /// Releases a lock on an item in the session data store
        /// </summary>
        /// <param name="context">HttpContext for the current request</param>
        /// <param name="id">Session ID for the session</param>
        /// <param name="lockId">The lock identifier for the current request</param>
        public override void ReleaseItemExclusive(
            HttpContext context,
            string id,
            object lockId)
        {
            ResponseStatus   status;
            var              retries = 0;
            var              tmp     = (ulong)lockId;
            SessionStateItem e;

            do
            {
                // Load the header for the item with CAS
                e = SessionStateItem.Load(_bucket, id, true);

                // Bail if the entry does not exist, or the lock ID does not match our lock ID
                if (e == null || e.LockId != tmp)
                {
                    break;
                }

                // Attempt to clear the lock for this item and loop around until we succeed
                e.LockId   = 0;
                e.LockTime = DateTime.MinValue;
            } while (!e.SaveHeader(_bucket, id, _exclusiveAccess, out status) && retries++ < _maxRetryCount && status != ResponseStatus.KeyNotFound);
        }
        private static SessionStateItem Get(IMemcachedClient client, bool acquireLock, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
        {
            locked  = false;
            lockId  = null;
            lockAge = TimeSpan.Zero;
            actions = SessionStateActions.None;

            var e = SessionStateItem.Load(client, id, false, _compressor, _isLoggingEnabled ? _logger : null);

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

            if (acquireLock)
            {
                // repeat until we can update the retrieved
                // item (i.e. nobody changes it between the
                // time we get it from the store and updates it s attributes)
                // Save() will return false if Cas() fails
                while (true)
                {
                    if (e.LockId > 0)
                    {
                        break;
                    }

                    actions = e.Flag;

                    e.LockId   = _exclusiveAccess ? e.HeadCas : 0;
                    e.LockTime = DateTime.UtcNow;
                    e.Flag     = SessionStateActions.None;

                    // try to update the item in the store
                    if (e.Save(client, id, true, _exclusiveAccess, _compressor, _isLoggingEnabled ? _logger : null))
                    {
                        locked = true;
                        lockId = e.LockId;

                        return(e);
                    }

                    // it has been modified between we loaded and tried to save it
                    e = SessionStateItem.Load(client, id, false, _compressor, _isLoggingEnabled ? _logger : null);
                    if (e == null)
                    {
                        return(null);
                    }
                }
            }

            locked  = true;
            lockAge = DateTime.UtcNow - e.LockTime;
            lockId  = e.LockId;
            actions = SessionStateActions.None;

            return(acquireLock ? null : e);
        }
        public override void RemoveItem(HttpContext context, string id, object lockId, SessionStateStoreData item)
        {
            var tmp = (ulong)lockId;
            var e   = SessionStateItem.Load(_client, id, true, _compressor, _isLoggingEnabled ? _logger : null);

            if (e != null && e.LockId == tmp)
            {
                SessionStateItem.Remove(_client, id);
            }
        }
        public override void RemoveItem(HttpContext context, string id, object lockId, SessionStateStoreData item)
        {
            var tmp = (ulong)lockId;
            var e   = SessionStateItem.Load(client, id, true);

            if (e != null && e.LockId == tmp)
            {
                SessionStateItem.Remove(client, id);
            }
        }
		private SessionStateItem Get(HttpContext context, bool acquireLock, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
		{
			locked = false;
			lockId = null;
			lockAge = TimeSpan.Zero;
			actions = SessionStateActions.None;

			var e = SessionStateItem.Load(this.client, id, false);
			if (e == null) return null;

			if (acquireLock)
			{
				// repeat until we can update the retrieved 
				// item (i.e. nobody changes it between the 
				// time we get it from the store and updates its attributes)
				// Save() will return false if Cas() fails
				while (true)
				{
					if (e.LockId > 0) break;

					actions = e.Flag;

					e.LockId = e.HeadCas;
					e.LockTime = DateTime.UtcNow;
					e.Flag = SessionStateActions.None;

					// try to update the item in the store
					if (e.Save(this.client, id, true, true))
					{
						locked = true;
						lockId = e.LockId;

						return e;
					}

					// it has been modifed between we loaded and tried to save it
					e = SessionStateItem.Load(this.client, id, false);
					if (e == null) return null;
				}
			}

			locked = true;
			lockAge = DateTime.UtcNow - e.LockTime;
			lockId = e.LockId;
			actions = SessionStateActions.None;

			return acquireLock ? null : e;
		}
        public override void ResetItemTimeout(HttpContext context, string id)
        {
            SessionStateItem e;

            do
            {
                // Load the item with CAS
                e = SessionStateItem.Load(_client, id, false, _compressor, _isLoggingEnabled ? _logger : null);
                if (e == null)
                {
                    break;
                }

                // Try to save with CAS, and loop around until we succeed
            } while (!e.Save(_client, id, false, _exclusiveAccess, _compressor, _isLoggingEnabled ? _logger : null));
        }
        public override void ResetItemTimeout(HttpContext context, string id)
        {
            SessionStateItem e;

            do
            {
                // Load the item with CAS
                e = SessionStateItem.Load(client, id, false);
                if (e == null)
                {
                    break;
                }

                // Try to save with CAS, and loop around until we succeed
            } while (!e.Save(client, id, false, exclusiveAccess));
        }
		public override void ReleaseItemExclusive(HttpContext context, string id, object lockId)
		{
			if (!(lockId is ulong))
				return;

			var tmp = (ulong)lockId;
			var e = SessionStateItem.Load(this.client, id, true);

			if (e != null && e.LockId == tmp)
			{
				e.LockId = 0;
				e.LockTime = DateTime.MinValue;

				e.Save(this.client, id, true, true);
			}
		}
Exemple #9
0
        /// <summary>
        /// Updates the session-item information in the session-state data store with values
        /// from the current request, and clears the lock on the data
        /// </summary>
        /// <param name="context">HttpContext for the current request</param>
        /// <param name="id">Session ID for the session</param>
        /// <param name="item">The session state item to be stored</param>
        /// <param name="lockId">The lock identifier for the current request</param>
        /// <param name="newItem">True if this is a new session item, false if it is an existing item</param>
        public override void SetAndReleaseItemExclusive(
            HttpContext context,
            string id,
            SessionStateStoreData item,
            object lockId,
            bool newItem)
        {
            bool             keyNotFound;
            var              retries = 0;
            SessionStateItem e;

            do
            {
                if (!newItem)
                {
                    var tmp = (ulong)lockId;

                    // Load the entire item with CAS (need the DataCas value also for the save)
                    e = SessionStateItem.Load(_bucket, id, false);

                    // if we're expecting an existing item, but
                    // it's not in the cache
                    // or it's locked by someone else, then quit
                    if (e == null || e.LockId != tmp)
                    {
                        return;
                    }
                }
                else
                {
                    // Create a new item if it requested
                    e = new SessionStateItem();
                }

                // Set the new data and reset the locks
                e.Timeout  = item.Timeout;
                e.Data     = (SessionStateItemCollection)item.Items;
                e.Flag     = SessionStateActions.None;
                e.LockId   = 0;
                e.LockTime = DateTime.MinValue;

                // Attempt to save with CAS and loop around if it fails
            } while (!e.SaveAll(_bucket, id, _exclusiveAccess && !newItem, out keyNotFound) && retries++ < _maxRetryCount && !keyNotFound);
        }
Exemple #10
0
        /// <summary>
        /// Updates the expiration date and time of an item in the session data store
        /// </summary>
        /// <param name="context">HttpContext for the current request</param>
        /// <param name="id">Session ID for the session</param>
        public override void ResetItemTimeout(
            HttpContext context,
            string id)
        {
            bool             keyNotFound;
            var              retries = 0;
            SessionStateItem e;

            do
            {
                // Load the item with CAS
                e = SessionStateItem.Load(_bucket, id, false);
                if (e == null)
                {
                    break;
                }

                // Try to save with CAS, and loop around until we succeed
            } while (!e.SaveAll(_bucket, id, _exclusiveAccess, out keyNotFound) && retries++ < _maxRetryCount && !keyNotFound);
        }
        public override void ReleaseItemExclusive(HttpContext context, string id, object lockId)
        {
            var tmp = (ulong)lockId;
            SessionStateItem e;

            do
            {
                // Load the header for the item with CAS
                e = SessionStateItem.Load(_client, id, true, _compressor, _isLoggingEnabled ? _logger : null);

                // Bail if the entry does not exist, or the lock ID does not match our lock ID
                if (e == null || e.LockId != tmp)
                {
                    break;
                }

                // Attempt to clear the lock for this item and loop around until we succeed
                e.LockId   = 0;
                e.LockTime = DateTime.MinValue;
            } while (!e.Save(_client, id, true, _exclusiveAccess, _compressor, _isLoggingEnabled ? _logger : null));
        }
		public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
		{
			SessionStateItem e = null;
			bool existing = false;

			if (!newItem)
			{
				if (!(lockId is ulong))
					return;

				var tmp = (ulong)lockId;
				e = SessionStateItem.Load(this.client, id, true);
				existing = e != null;

				// if we're expecting an existing item, but
				// it's not in the cache
				// or it's not locked
				// or it's locked by someone else, then quit
				if (!newItem
					&& (!existing
						|| e.LockId == 0
						|| e.LockId != tmp))
					return;
			}

			if (!existing) e = new SessionStateItem();

			// set the new data and reset the locks
			e.Timeout = item.Timeout;
			e.Data = (SessionStateItemCollection)item.Items;
			e.Flag = SessionStateActions.None;
			e.LockId = 0;
			e.LockTime = DateTime.MinValue;

			e.Save(this.client, id, false, existing && !newItem);
		}
Exemple #13
0
        /// <summary>
        /// Retrieves the session data from the data source. If the lockRecord parameter is true
        /// (in the case of GetItemExclusive), then the record is locked and we return a new lockId
        /// and lockAge.
        /// </summary>
        /// <param name="bucket">Reference to the couchbase bucket we are using</param>
        /// <param name="context">HttpContext for the current request</param>
        /// <param name="acquireLock">True to aquire the lock, false to not aquire it</param>
        /// <param name="id">Session ID for the session</param>
        /// <param name="locked">Returns true if the session item is locked, otherwise false</param>
        /// <param name="lockAge">Returns the amount of time that the item has been locked</param>
        /// <param name="lockId">Returns lock identifier for the current request</param>
        /// <param name="actions">Indicates whether the current sessions is an uninitialized, cookieless session</param>
        /// <returns>SessionStateItem object containing the session state data</returns>
        public static SessionStateItem GetSessionStoreItem(
            IBucket bucket,
            HttpContext context,
            bool acquireLock,
            string id,
            out bool locked,
            out TimeSpan lockAge,
            out object lockId,
            out SessionStateActions actions)
        {
            locked  = false;
            lockId  = null;
            lockAge = TimeSpan.Zero;
            actions = SessionStateActions.None;

            var e = SessionStateItem.Load(bucket, id, false);

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

            if (acquireLock)
            {
                // repeat until we can update the retrieved
                // item (i.e. nobody changes it between the
                // time we get it from the store and updates it s attributes)
                // Save() will return false if Cas() fails
                while (true)
                {
                    if (e.LockId > 0)
                    {
                        break;
                    }

                    actions = e.Flag;

                    e.LockId   = _exclusiveAccess ? e.HeadCas : 0;
                    e.LockTime = DateTime.UtcNow;
                    e.Flag     = SessionStateActions.None;

                    ResponseStatus status;
                    // try to update the item in the store
                    if (e.SaveHeader(bucket, id, _exclusiveAccess, out status))
                    {
                        locked = true;
                        lockId = e.LockId;

                        return(e);
                    }
                    if (status == ResponseStatus.KeyNotFound)
                    {
                        break;
                    }

                    // it has been modified between we loaded and tried to save it
                    e = SessionStateItem.Load(bucket, id, false);
                    if (e == null)
                    {
                        return(null);
                    }
                }
            }

            locked  = true;
            lockAge = DateTime.UtcNow - e.LockTime;
            lockId  = e.LockId;
            actions = SessionStateActions.None;

            return(acquireLock ? null : e);
        }
		public override void ResetItemTimeout(HttpContext context, string id)
		{
			var e = SessionStateItem.Load(this.client, id, false);
			if (e != null)
				e.Save(this.client, id, false, true);
		}