* HttpCachePolicy.cs: Add an event that is fired when the
authorJackson Harper <jackson@novell.com>
Thu, 15 Jan 2004 03:50:30 +0000 (03:50 -0000)
committerJackson Harper <jackson@novell.com>
Thu, 15 Jan 2004 03:50:30 +0000 (03:50 -0000)
cacheability is updated. The response uses this to determine
whether or not it needs to cache itself.
* HttpResponse.cs: When the cacheability is updated either create
or dispose of the cached raw response based on whether or not we
wil need it. This allows output caching to be controlled
programatically.

svn path=/trunk/mcs/; revision=22089

mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpCachePolicy.cs
mcs/class/System.Web/System.Web/HttpResponse.cs

index 2d3be9afd6823d9abb68da85724be3c09bce09ca..c090161618b1df1e19c1d5b9fd6f2859ee6ddad2 100644 (file)
@@ -1,3 +1,13 @@
+2004-01-14  Jackson Harper <jackson@ximian.com>
+
+       * HttpCachePolicy.cs: Add an event that is fired when the
+       cacheability is updated. The response uses this to determine
+       whether or not it needs to cache itself.
+       * HttpResponse.cs: When the cacheability is updated either create
+       or dispose of the cached raw response based on whether or not we
+       wil need it. This allows output caching to be controlled
+       programatically.
+       
 2004-01-12  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * HttpContext.cs: add setter for ConfigTimeout.
index 98cea403f3a9ac16ac0eee2bde424bfb6865b4f0..ff45ba9e650f7c8e8d70ff858db51d91898d6692 100644 (file)
@@ -13,6 +13,19 @@ using System.Web.UI;
 using System.Web.Util;\r
 \r
 namespace System.Web {\r
+\r
+       public class CacheabilityUpdatedEventArgs : EventArgs {\r
+\r
+               public readonly HttpCacheability Cacheability;\r
+\r
+               public CacheabilityUpdatedEventArgs (HttpCacheability cacheability)\r
+               {\r
+                       Cacheability = cacheability;\r
+               }\r
+       }\r
+       \r
+       internal delegate void CacheabilityUpdatedCallback (object sender, CacheabilityUpdatedEventArgs args);\r
+       \r
        public sealed class HttpCachePolicy {\r
 \r
                internal HttpCachePolicy ()\r
@@ -46,11 +59,13 @@ namespace System.Web {
                TimeSpan proxyMaxAge;\r
                ArrayList fields;\r
                bool slidingExpiration;\r
-               \r
+                \r
                #endregion\r
 \r
+                internal event CacheabilityUpdatedCallback CacheabilityUpdated;\r
+                \r
                #region Properties\r
-\r
+                \r
                public HttpCacheVaryByHeaders VaryByHeaders {\r
                        get { return varyByHeaders; }\r
                }\r
@@ -98,6 +113,9 @@ namespace System.Web {
                                return;\r
                        \r
                        this.cacheability = cacheability;\r
+\r
+                       if (CacheabilityUpdated != null)\r
+                               CacheabilityUpdated (this, new CacheabilityUpdatedEventArgs (cacheability));\r
                }\r
 \r
                public void SetCacheability (HttpCacheability cacheability, string field)\r
index 9cec87a92f2ff7fa3c719b018ec8fc3b8aa49abd..6d7f8898bfd4c8a987ca4bb1e2b9677b139efd2e 100644 (file)
@@ -148,10 +148,6 @@ namespace System.Web
                internal bool IsCached {
                        get { return cached_response != null; }
                }
-               
-               internal void CacheResponse (HttpRequest request) {
-                       cached_response = new CachedRawResponse (_CachePolicy);
-               }
 
                internal CachedRawResponse GetCachedResponse () {
                        cached_response.StatusCode = StatusCode;
@@ -379,13 +375,24 @@ namespace System.Web
                public HttpCachePolicy Cache
                {
                        get {
-                               if (null == _CachePolicy)
+                               if (null == _CachePolicy) {
                                        _CachePolicy = new HttpCachePolicy ();
+                                       _CachePolicy.CacheabilityUpdated += new CacheabilityUpdatedCallback (
+                                               OnCacheabilityUpdated);
+                               }
 
                                return _CachePolicy;
                        }
                }
 
+               private void OnCacheabilityUpdated (object sender, CacheabilityUpdatedEventArgs e)
+               {
+                       if (e.Cacheability >= HttpCacheability.Server && !IsCached)
+                               cached_response = new CachedRawResponse (_CachePolicy);
+                       else if (e.Cacheability <= HttpCacheability.Private)
+                               cached_response = null;
+               }
+               
                [MonoTODO("Set status in the cache policy")]
                public string CacheControl
                {