private SessionStateStoreData CreateSessionStateStoreData(
                                       HttpContext context, SessionStateActions actions,
                                       SessionData sessionData)
        {
            if (actions == SessionStateActions.None)
            {
                var sessionItems = BytesToSessionStateItemCollection(
                                                        sessionData.SerializedContent);

                return new SessionStateStoreData(
                                sessionItems,
                                SessionStateUtility.GetSessionStaticObjects(context),
                                sessionData.Timeout);
            }
            else
            {
                return new SessionStateStoreData(
                                new SessionStateItemCollection(),
                                SessionStateUtility.GetSessionStaticObjects(context),
                                sessionData.Timeout);
            }
        }
        /// <summary>
        /// <para>
        /// Takes as input the HttpContext instance for the current request, the 
        /// SessionID value for the current request, a SessionStateStoreData object that
        /// contains the current session values to be stored, the lock identifier for 
        /// the current request, and a value that indicates whether the data to be 
        /// stored is for a new session or an existing session.
        /// </para>
        /// 
        /// <para>
        /// If the newItem parameter is true, the SetAndReleaseItemExclusive method 
        /// inserts a new item into the data store with the supplied values. Otherwise, 
        /// the existing item in the data store is updated with the supplied values, 
        /// and any lock on the data is released. Note that only session data for the 
        /// current application that matches the supplied SessionID value and lock 
        /// identifier values is updated.
        /// </para>
        /// 
        /// <para>
        /// After the SetAndReleaseItemExclusive method is called, the ResetItemTimeout 
        /// method is called by SessionStateModule to update the expiration date and 
        /// time of the session-item data.
        /// </para>
        /// </summary>
        public override void SetAndReleaseItemExclusive(
                                HttpContext context, string id,
                                SessionStateStoreData item,
                                object lockId, bool newItem)
        {
            var serializedContent = SessionStateItemCollectionToBytes(
                                                (SessionStateItemCollection)item.Items);
            if (newItem)
            {
                var sessionData = new SessionData(item.Timeout, serializedContent);
                _memcachedClient.Store(StoreMode.Set, id, sessionData,
                                                    TimeSpan.FromMinutes(item.Timeout));
            }
            else
            {
                var sessionData = _memcachedClient.Get<SessionData>(id);

                if (sessionData == null
                    || sessionData.LockId != (int)lockId)
                {
                    return;
                }

                sessionData.Locked = false;
                sessionData.SerializedContent = serializedContent;
                _memcachedClient.Store(StoreMode.Set, id, sessionData,
                                                TimeSpan.FromSeconds(sessionData.Timeout));
            }
        }