From: Jackson Harper Date: Thu, 15 Jan 2004 03:50:30 +0000 (-0000) Subject: * HttpCachePolicy.cs: Add an event that is fired when the X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=2cde9249cb9ac211f845acc3138e1be5ea24a7da;p=mono.git * 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. svn path=/trunk/mcs/; revision=22089 --- diff --git a/mcs/class/System.Web/System.Web/ChangeLog b/mcs/class/System.Web/System.Web/ChangeLog index 2d3be9afd68..c090161618b 100644 --- a/mcs/class/System.Web/System.Web/ChangeLog +++ b/mcs/class/System.Web/System.Web/ChangeLog @@ -1,3 +1,13 @@ +2004-01-14 Jackson Harper + + * 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 * HttpContext.cs: add setter for ConfigTimeout. diff --git a/mcs/class/System.Web/System.Web/HttpCachePolicy.cs b/mcs/class/System.Web/System.Web/HttpCachePolicy.cs index 98cea403f3a..ff45ba9e650 100644 --- a/mcs/class/System.Web/System.Web/HttpCachePolicy.cs +++ b/mcs/class/System.Web/System.Web/HttpCachePolicy.cs @@ -13,6 +13,19 @@ using System.Web.UI; using System.Web.Util; namespace System.Web { + + public class CacheabilityUpdatedEventArgs : EventArgs { + + public readonly HttpCacheability Cacheability; + + public CacheabilityUpdatedEventArgs (HttpCacheability cacheability) + { + Cacheability = cacheability; + } + } + + internal delegate void CacheabilityUpdatedCallback (object sender, CacheabilityUpdatedEventArgs args); + public sealed class HttpCachePolicy { internal HttpCachePolicy () @@ -46,11 +59,13 @@ namespace System.Web { TimeSpan proxyMaxAge; ArrayList fields; bool slidingExpiration; - + #endregion + internal event CacheabilityUpdatedCallback CacheabilityUpdated; + #region Properties - + public HttpCacheVaryByHeaders VaryByHeaders { get { return varyByHeaders; } } @@ -98,6 +113,9 @@ namespace System.Web { return; this.cacheability = cacheability; + + if (CacheabilityUpdated != null) + CacheabilityUpdated (this, new CacheabilityUpdatedEventArgs (cacheability)); } public void SetCacheability (HttpCacheability cacheability, string field) diff --git a/mcs/class/System.Web/System.Web/HttpResponse.cs b/mcs/class/System.Web/System.Web/HttpResponse.cs index 9cec87a92f2..6d7f8898bfd 100644 --- a/mcs/class/System.Web/System.Web/HttpResponse.cs +++ b/mcs/class/System.Web/System.Web/HttpResponse.cs @@ -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 {