/// <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(); } } }
/// <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(); } } }