Browse Source

2008-03-18 Geoff Norton <[email protected]>

	* Cache.cs:  MS allows calling Insert in a removed handler, we need to
	avoid double locking here otherwise the Insert will never succeed.


svn path=/trunk/mcs/; revision=98559
Geoff Norton 18 years ago
parent
commit
1efe2c5419

+ 20 - 19
mcs/class/System.Web/System.Web.Caching/Cache.cs

@@ -178,35 +178,36 @@ namespace System.Web.Caching
 		
 		object Remove (string key, CacheItemRemovedReason reason)
 		{
-			lock (cache) {
-				CacheItem it;
+			CacheItem it = null;
 
+			lock (cache) {
 #if NET_2_0
 				cache.TryGetValue (key, out it);
 #else
 				it = (CacheItem) cache [key];
 #endif
 				
-				if (it != null) {
-					if (it.Dependency != null) {
+				cache.Remove (key);
+			}
+
+			if (it != null) {
+				if (it.Dependency != null) {
 #if NET_2_0
-						it.Dependency.SetCache (null);
+					it.Dependency.SetCache (null);
 #endif
-						it.Dependency.DependencyChanged -= new EventHandler (OnDependencyChanged);
-						it.Dependency.Dispose ();
-					}
-					cache.Remove (key);
-					if (it.OnRemoveCallback != null) {
-						try {
-							it.OnRemoveCallback (key, it.Value, reason);
-						} catch {
-							//TODO: anything to be done here?
-						}
+					it.Dependency.DependencyChanged -= new EventHandler (OnDependencyChanged);
+					it.Dependency.Dispose ();
+				}
+				if (it.OnRemoveCallback != null) {
+					try {
+						it.OnRemoveCallback (key, it.Value, reason);
+					} catch {
+						//TODO: anything to be done here?
 					}
-					return it.Value;
-				} else
-					return null;
-			}
+				}
+				return it.Value;
+			} else
+				return null;
 		}
 
 		// Used when shutting down the application so that

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

@@ -1,3 +1,8 @@
+2008-03-18  Geoff Norton  <[email protected]>
+
+	* Cache.cs:  MS allows calling Insert in a removed handler, we need to
+	avoid double locking here otherwise the Insert will never succeed.
+
 2008-02-26  Kornél Pál  <[email protected]>
 
 	* CachedRawResponse.cs, OutputCacheModule.cs: Don't add Date header because