internal class CachedRawResponse {
private HttpCachePolicy policy;
+ private CachedVaryBy varyby;
private int status_code;
private string status_desc;
private int content_length;
internal CachedRawResponse (HttpCachePolicy policy)
{
this.policy = policy;
+ this.varyby = varyby;
this.buffer = new byte [HttpWriter.MaxBufferSize];
}
get { return policy; }
set { policy = value; }
}
-
+
+ internal CachedVaryBy VaryBy {
+ get { return varyby; }
+ set { varyby = value; }
+ }
+
internal int StatusCode {
get { return status_code; }
set { status_code = value; }
using System;
using System.Text;
+using System.Collections;
namespace System.Web.Caching {
private string[] prms;
private string[] headers;
private string custom;
-
- internal CachedVaryBy (HttpCachePolicy policy)
+ private string key;
+ private ArrayList item_list;
+
+ internal CachedVaryBy (HttpCachePolicy policy, string key)
{
prms = policy.VaryByParams.GetParamNames ();
headers = policy.VaryByHeaders.GetHeaderNames ();
custom = policy.GetVaryByCustom ();
+ this.key = key;
+ item_list = new ArrayList ();
+ }
+
+ internal ArrayList ItemList {
+ get { return item_list; }
}
+ internal string Key {
+ get { return key; }
+ }
+
internal string CreateKey (string file_path, HttpContext context)
{
StringBuilder builder = new StringBuilder ();
+2004-01-11 Jackson Harper <jackson@ximian.com>
+
+ * OutputCacheModule.cs: Remove varyby objects when there are no
+ more raw responses that belong to them.
+ * CachedRawResponse.cs: Keep a reference to the VaryBy object that
+ this response belongs to this is so the varyby can be cleaned up.
+ * CachedVaryBy.cs: Keep a reference to the keys that belong to the
+ varyby and a reference to the varyby's key.
+
2004-01-04 Jackson Harper <jackson@ximian.com>
* OutputCacheModule.cs: Dont cache items when trace is enabled.
using System.Web;
using System.Web.Util;
+using System.Collections;
namespace System.Web.Caching {
internal sealed class OutputCacheModule : IHttpModule {
+ private CacheItemRemovedCallback response_removed;
+
public OutputCacheModule ()
{
}
app.AddOnUpdateRequestCacheAsync (
new BeginEventHandler (OnBeginUpdateCache),
new EndEventHandler (OnEndUpdateCache));
+
+ response_removed = new CacheItemRemovedCallback (OnRawResponseRemoved);
}
IAsyncResult OnBeginRequestCache (object o, EventArgs args, AsyncCallback cb, object data)
bool lookup = true;
if (varyby == null) {
- varyby = new CachedVaryBy (context.Response.Cache);
+ int secs = (ideal_duration > context.Response.Cache.Duration ?
+ ideal_duration : context.Response.Cache.Duration);
+ varyby = new CachedVaryBy (context.Response.Cache, vary_key);
context.Cache.InsertPrivate (vary_key, varyby, null,
- Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
+ Cache.NoAbsoluteExpiration,
+ Cache.NoSlidingExpiration,
CacheItemPriority.Normal, null);
lookup = false;
}
context.Cache.InsertPrivate (key, c, new CacheDependency (files, keys),
context.Response.Cache.Expires,
Cache.NoSlidingExpiration,
- CacheItemPriority.Normal, null);
+ CacheItemPriority.Normal, response_removed);
+ c.VaryBy = varyby;
+ varyby.ItemList.Add (key);
}
}
+ private void OnRawResponseRemoved (string key, object value, CacheItemRemovedReason reason)
+ {
+ CachedRawResponse c = (CachedRawResponse) value;
+
+ c.VaryBy.ItemList.Remove (key);
+ if (c.VaryBy.ItemList.Count != 0)
+ return;
+
+ Cache cache = HttpRuntime.Cache;
+ cache.Remove (c.VaryBy.Key);
+ }
+
private bool IsExpired (HttpContext context, CachedRawResponse crr)
{
if (crr == null || context.Timestamp > crr.Policy.Expires)