+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.
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
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
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
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;
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
{