Parcourir la source

2008-04-28 Marek Habersack <[email protected]>

	* Cache.cs: refactoring - move the timeout setting code to
	separate methods, so that it can be accessed from outside the
	class. Fixes bug #382644

2008-04-28  Marek Habersack  <[email protected]>

	* ISessionHandler.cs: added new method, Touch, to reset the item
	timeout.

	* SessionStateServerHandler.cs, SessionSQLServerHandler.cs,
	SessionInProcHandler.cs: added implementation of the
	ISessionHandler Touch method, to reset item timeout. Fixes bug
	#382644

	* StateServerItem.cs: made the Timeout property writable.

	* SessionStateModule.cs: reset the item timeout after
	OnSessionStart has returned. Fixes bug #382644

	* RemoteStateServer.cs: added a method to reset item timeout.

svn path=/trunk/mcs/; revision=102034
Marek Habersack il y a 17 ans
Parent
commit
b92349a289

+ 33 - 4
mcs/class/System.Web/System.Web.Caching/Cache.cs

@@ -152,17 +152,46 @@ namespace System.Web.Caching
 				dependencies.DependencyChanged += new EventHandler (OnDependencyChanged);
 				dependencies.SetCache (DependencyCache);
 			}
+
+			ci.Priority = priority;
+			SetItemTimeout (ci, absoluteExpiration, slidingExpiration, onRemoveCallback, key);
+		}
+
+		internal void SetItemTimeout (string key, DateTime absoluteExpiration, TimeSpan slidingExpiration)
+		{
+			CacheItem ci = null;
+
+			lock (cache) {
+#if NET_2_0
+				cache.TryGetValue (key, out ci);
+#else
+				ci = (CacheItem) cache [key];
+#endif
+			}
+
+			if (ci != null)
+				SetItemTimeout (ci, absoluteExpiration, slidingExpiration, ci.OnRemoveCallback, null);
+		}
+
+		void SetItemTimeout (CacheItem ci, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemRemovedCallback onRemoveCallback, string key)
+		{
 			ci.SlidingExpiration = slidingExpiration;
 			if (slidingExpiration != NoSlidingExpiration)
 				ci.AbsoluteExpiration = DateTime.Now + slidingExpiration;
 			else
-				ci.AbsoluteExpiration = absoluteExpiration;
-			
-			ci.Priority = priority;
+				ci.AbsoluteExpiration = absoluteExpiration;			
+
 			ci.OnRemoveCallback = onRemoveCallback;
 			
 			lock (cache) {
-				cache [key] = ci;
+				if (ci.Timer != null) {
+					ci.Timer.Dispose ();
+					ci.Timer = null;
+				}
+
+				if (key != null)
+					cache [key] = ci;
+				
 				ci.LastChange = DateTime.Now;
 				if (ci.AbsoluteExpiration != NoAbsoluteExpiration) {
 					int remaining = Math.Max (0, (int)(ci.AbsoluteExpiration - DateTime.Now).TotalMilliseconds);

+ 6 - 0
mcs/class/System.Web/System.Web.Caching/ChangeLog

@@ -1,3 +1,9 @@
+2008-04-28  Marek Habersack  <[email protected]>
+
+	* Cache.cs: refactoring - move the timeout setting code to
+	separate methods, so that it can be accessed from outside the
+	class. Fixes bug #382644
+
 2008-03-18  Geoff Norton  <[email protected]>
 
 	* Cache.cs:  MS allows calling Insert in a removed handler, we need to

+ 17 - 0
mcs/class/System.Web/System.Web.SessionState/ChangeLog

@@ -1,3 +1,20 @@
+2008-04-28  Marek Habersack  <[email protected]>
+
+	* ISessionHandler.cs: added new method, Touch, to reset the item
+	timeout.
+
+	* SessionStateServerHandler.cs, SessionSQLServerHandler.cs,
+	SessionInProcHandler.cs: added implementation of the
+	ISessionHandler Touch method, to reset item timeout. Fixes bug
+	#382644
+
+	* StateServerItem.cs: made the Timeout property writable.
+
+	* SessionStateModule.cs: reset the item timeout after
+	OnSessionStart has returned. Fixes bug #382644
+
+	* RemoteStateServer.cs: added a method to reset item timeout.
+
 2007-12-13  Marek Habersack  <[email protected]>
 
 	* SessionId.cs: speed optimization - use String.Concat instead of

+ 1 - 2
mcs/class/System.Web/System.Web.SessionState/HttpSessionState.cs

@@ -73,9 +73,8 @@ public sealed class HttpSessionState : ICollection, IEnumerable
 	{
 		return new HttpSessionState (_id, _dict.Clone (), _staticObjects, _timeout, _newSession,
 					     _isCookieless, _mode, _isReadonly);
-
 	}
-
+	
 	public int CodePage {
 		get {
 			HttpContext current = HttpContext.Current;

+ 1 - 0
mcs/class/System.Web/System.Web.SessionState/ISessionHandler.cs

@@ -48,6 +48,7 @@ namespace System.Web.SessionState
 						bool read_only, ref bool isNew);
 
 		void UpdateHandler (HttpContext context, SessionStateModule module);
+		void Touch (string sessionId, int timeout);
 	}
 }
 

+ 9 - 0
mcs/class/System.Web/System.Web.SessionState/RemoteStateServer.cs

@@ -65,6 +65,15 @@ namespace System.Web.SessionState {
 			item.DictionaryData = dict_data;
 			item.StaticObjectsData = sobjs_data;
 		}
+
+		internal void Touch (string id, int timeout)
+		{
+			StateServerItem item = Get (id);
+			if (item == null)
+				return;
+			item.Timeout = timeout;
+			cache.SetItemTimeout (id, Cache.NoAbsoluteExpiration, new TimeSpan (0, item.Timeout, 0));
+		}
 		
 		internal StateServerItem Get (string id)
 		{

+ 12 - 1
mcs/class/System.Web/System.Web.SessionState/SessionInProcHandler.cs

@@ -40,6 +40,8 @@ namespace System.Web.SessionState
 {
 	class SessionInProcHandler : ISessionHandler
 	{
+		const string INPROC_CACHE_PREFIX = "@@@InProc@";
+		
 		SessionConfig config;
 		CacheItemRemovedCallback removedCB;
 		
@@ -89,12 +91,21 @@ namespace System.Web.SessionState
 						read_only); //readonly
 
 			TimeSpan timeout = new TimeSpan (0, config.Timeout, 0);
-			cache.Insert ("@@@InProc@" + sessionID, state, null, Cache.NoAbsoluteExpiration,
+			cache.Insert (INPROC_CACHE_PREFIX + sessionID, state, null, Cache.NoAbsoluteExpiration,
 				      timeout, CacheItemPriority.AboveNormal, removedCB);
 
 			isNew = true;
 			return state;
 		}
+
+		public void Touch (string sessionId, int timeout)
+		{
+			Cache cache = HttpRuntime.InternalCache;
+			if (cache == null || sessionId == null || sessionId.Length == 0)
+				return;
+			
+			cache.SetItemTimeout (INPROC_CACHE_PREFIX + sessionId, Cache.NoAbsoluteExpiration, new TimeSpan (0, timeout, 0));
+		}
 	}
 }
 

+ 13 - 0
mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs

@@ -147,6 +147,19 @@ namespace System.Web.SessionState {
 			return session;
 		}
 
+		public void Touch (string sessionId, int timeout)
+		{
+			HttpContext ctx = HttpContext.Current;
+			if (ctx == null)
+				return;
+			
+			HttpSessionState session = ctx.Session;
+			if (session == null)
+				return;
+			
+			UpdateSession (sessionId, timeout, session.SessionDictionary);
+		}
+		
 		private void GetConnectionData (out string providerAssembly,
 				out string cncTypeName, out string cncString)
 		{

+ 6 - 1
mcs/class/System.Web/System.Web.SessionState/SessionStateModule.cs

@@ -212,8 +212,13 @@ static private SessionConfig config {
 					context.Response.AppendCookie (cookie);
 				}
 
-				if (isNew)
+				if (isNew) {
 					OnSessionStart ();
+					HttpSessionState hss = application.Session;
+					
+					if (hss != null)
+						handler.Touch (hss.SessionID, hss.Timeout);
+				}
 			}
 		}
 

+ 8 - 0
mcs/class/System.Web/System.Web.SessionState/SessionStateServerHandler.cs

@@ -143,6 +143,14 @@ namespace System.Web.SessionState {
 			return session;
 		}
 
+		public void Touch (string sessionId, int timeout)
+		{
+			if (state_server == null)
+				return;
+
+			state_server.Touch (sessionId, timeout);
+		}
+		
 		private string GetId (HttpContext context)
 		{
 			if (!config.CookieLess &&

+ 1 - 0
mcs/class/System.Web/System.Web.SessionState/StateServerItem.cs

@@ -71,6 +71,7 @@ namespace System.Web.SessionState {
 
 		public int Timeout {
 			get { return timeout; }
+			set { timeout = value; }
 		}
 	}
 }