Ejemplo n.º 1
0
        /// <summary>
        /// Fills NCache from the system ASP.NET session.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="session"></param>
        /// <param name="strict"></param>
        /// <param name="async"></param>
        void IDistributionStrategy.FillCacheFromSession(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict, bool isAbandoned)
        {
            if (cache == null)
            {
                return;
            }

            string     sessionId = session.SessionID;
            SessionKey key       = new SessionKey(sessionId, module.ApplicationId);

            try
            {
                if (session.Count == 0) //We need not to keep any empty session in the cache.  (This is incomplete. As it is never used. See Monolithic strategy for detail use-case)
                {
                    return;
                }

                cache.Remove(sessionId, key.ToString(), false);
                cache.Insert(sessionId, key.ToString(), DateTime.Now, null, Alachisoft.NCache.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(session.Timeout), CacheItemPriority.NotRemovable);

                string[] tempStrArr = new string[1];
                tempStrArr[0] = key.ToString();
                foreach (string skey in session.Keys)
                {
                    cache.Insert(sessionId, SessionKey.CompositeKey(sessionId, skey), session[skey], new CacheDependency(null, tempStrArr), Alachisoft.NCache.Web.Caching.Cache.NoAbsoluteExpiration, Alachisoft.NCache.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable);
                }

                if (strict)
                {
                    session.Clear();
                }
            }
            catch (Exception exc)
            {
                module.RaiseExceptions(exc, "SingleValueDistribution.FillCacheFromSession");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fills the system ASP.NET session from NCache.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="cache"></param>
        /// <param name="strict"></param>
        void IDistributionStrategy.FillSessionFromCache(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict)
        {
            try
            {
                string sessionId = session.SessionID;
                if (strict)
                {
                    session.Clear();
                }

                IDictionaryEnumerator i = (IDictionaryEnumerator)cache.GetEnumerator();
                while (i != null && i.MoveNext())
                {
                    SessionKey key = i.Key as SessionKey;
                    if (key != null && key.SessionID == sessionId)
                    {
                        session[key.Key] = i.Value;
                    }
                }
            }
            catch (Exception exc)
            {
                if (strict)
                {
                    session.Clear();
                }
                module.RaiseExceptions(exc, "SingleValueDistribution.FillSessionFromCache");
            }
        }
Ejemplo n.º 3
0
/// <summary>
/// Fills the system ASP.NET session from NCache.
/// </summary>
/// <param name="session"></param>
/// <param name="cache"></param>
/// <param name="strict"></param>

        void IDistributionStrategy.FillSessionFromCache(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict)
        {
            string sessionId = session.SessionID;

            SessionKey key = new SessionKey(sessionId, module.ApplicationId);

            if (strict)
            {
                session.Clear();
            }

            /// save the binary form of data, for comparision on FillCacheFromAspNet()
            _table = (byte[])cache.Get(key.ToString());

            if (_table == null)
            {
                _isNewSession = true;
                return;
            }

            Hashtable ht = (Hashtable)CompactBinaryFormatter.FromByteBuffer(_table, module.CacheID);

            if (ht == null)
            {
                return;
            }

            IDictionaryEnumerator i = ht.GetEnumerator();

            while (i.MoveNext())
            {
                session[i.Key.ToString()] = i.Value;
            }
        }
Ejemplo n.º 4
0
/// <summary>
/// Fills NCache from the system ASP.NET session.
/// </summary>
/// <param name="cache"></param>
/// <param name="session"></param>
/// <param name="strict"></param>
/// <param name="async"></param>

        void IDistributionStrategy.FillCacheFromSession(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict, bool isAbandoned)
        {
            string     sessionId = session.SessionID;
            SessionKey key       = new SessionKey(sessionId, module.ApplicationId);

            try
            {
                if (session.IsReadOnly && cache.Contains(sessionId, key.ToString()) && !isAbandoned)
                {
                    return;
                }

                if (/*session.Count == 0 ||*/ isAbandoned)//[Ata]: Session is not removed from store if it is cleared
                {
                    cache.Remove(sessionId, key.ToString(), false);
                    if (module.DetailedLogsEnabled)
                    {
                        NSessionStateModule.NCacheLog.Debug(sessionId + " :session removed from cache");
                    }
                    return;
                }

                //use-case: A session my get emptied while doing different updates... although whien added first time is is not empty
                //So we must update that session rather doing no operation thinking it is empty session and need not to be added.
                if (session.Count == 0 && _isNewSession) //We need not to keep any new empty session in the cache. [Asif Imam] April 09, 08
                {
                    return;
                }

                IDictionary ht = new Hashtable();
                foreach (string skey in session.Keys)
                {
                    ht[skey] = session[skey];
                }

                byte[] _stable = CompactBinaryFormatter.ToByteBuffer(ht, module.CacheID);

                if (_table != null)
                {
                    if (BinaryComparer(_stable, _table))
                    {
                        return;
                    }
                }

                CacheItem sessionItem = new CacheItem(_stable);
                sessionItem.Priority = CacheItemPriority.NotRemovable;

                sessionItem.Expiration = new Runtime.Caching.Expiration(Runtime.Caching.ExpirationType.Sliding, TimeSpan.FromMinutes(session.Timeout));
                cache.Insert(sessionId, key.ToString(), sessionItem, false);
            }
            finally
            {
                if (session != null && strict)
                {
                    session.Clear();
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Fills NCache from the system ASP.NET session.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="session"></param>
        /// <param name="strict"></param>
        /// <param name="async"></param>
        void IDistributionStrategy.FillCacheFromSession(ISessionCache cache, HttpSessionState session, NSessionStateModule module, bool strict, bool isAbandoned)
        {
            string     sessionId = session.SessionID;
            SessionKey key       = new SessionKey(sessionId, module.ApplicationId);

            try
            {
                if (session.IsReadOnly && cache.Contains(sessionId, key.ToString()) && !isAbandoned)
                {
                    return;
                }

                if (isAbandoned)// Session is not removed from store if it is cleared
                {
                    cache.Remove(sessionId, key.ToString(), false);
                    if (module.DetailedLogsEnabled)
                    {
                        NSessionStateModule.NCacheLog.Debug(sessionId + " :session removed from cache");
                    }
                    return;
                }

                if (session.Count == 0 && _isNewSession) //We need not to keep any new empty session in the cache.
                {
                    return;
                }

                IDictionary ht = new Hashtable();
                foreach (string skey in session.Keys)
                {
                    ht[skey] = session[skey];
                }

                byte[] _stable = CompactBinaryFormatter.ToByteBuffer(ht, module.CacheID);

                if (_table != null)
                {
                    if (BinaryComparer(_stable, _table))
                    {
                        return;
                    }
                }

                CacheItem sessionItem = new CacheItem(_stable);
                sessionItem.Priority = CacheItemPriority.NotRemovable;

                sessionItem.SlidingExpiration = TimeSpan.FromMinutes(session.Timeout);
                cache.Insert(sessionId, key.ToString(), sessionItem, false);
            }
            finally
            {
                if (session != null && strict)
                {
                    session.Clear();
                }
            }
        }