* OutputCacheModule.cs: Remove varyby objects when there are no
authorJackson Harper <jackson@novell.com>
Mon, 12 Jan 2004 02:58:21 +0000 (02:58 -0000)
committerJackson Harper <jackson@novell.com>
Mon, 12 Jan 2004 02:58:21 +0000 (02:58 -0000)
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.

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

mcs/class/System.Web/System.Web.Caching/CachedRawResponse.cs
mcs/class/System.Web/System.Web.Caching/CachedVaryBy.cs
mcs/class/System.Web/System.Web.Caching/ChangeLog
mcs/class/System.Web/System.Web.Caching/OutputCacheModule.cs

index c367994fbef75e6f60384e7158e183d6b3e484f2..6e315a55e286c53d72da33050ab79f7cde3f8f39 100644 (file)
@@ -17,6 +17,7 @@ namespace System.Web.Caching {
        internal class CachedRawResponse {
 
                private HttpCachePolicy policy;
+               private CachedVaryBy varyby;
                private int status_code;
                private string status_desc;
                private int content_length;
@@ -27,6 +28,7 @@ namespace System.Web.Caching {
                internal CachedRawResponse (HttpCachePolicy policy)
                {
                        this.policy = policy;
+                       this.varyby = varyby;
                        this.buffer = new byte [HttpWriter.MaxBufferSize];
                }
 
@@ -34,7 +36,12 @@ namespace System.Web.Caching {
                        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; }
index d2a134992da3bd827a158cbc2a173cbf99a93b25..04242a2786751863409d40f5100353d22a2a5f49 100644 (file)
@@ -10,6 +10,7 @@
 
 using System;
 using System.Text;
+using System.Collections;
 
 namespace System.Web.Caching {
 
@@ -18,14 +19,26 @@ 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 ();
index 26dd465dcb994d2c6a42ebfd460182afb4e78376..a09e43cd23c6aa0f1e684eee663e9f318165350e 100644 (file)
@@ -1,3 +1,12 @@
+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.
index c8783e5d63477631b578a8387c47461a0b2d608b..1b59e598f9e193bfb6124672b10115211def5f1f 100644 (file)
@@ -9,11 +9,14 @@
 
 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 ()
                {
                }
@@ -31,6 +34,8 @@ namespace System.Web.Caching {
                        app.AddOnUpdateRequestCacheAsync (
                                new BeginEventHandler (OnBeginUpdateCache),
                                new EndEventHandler (OnEndUpdateCache));
+                       response_removed = new CacheItemRemovedCallback (OnRawResponseRemoved);
                }
 
                IAsyncResult OnBeginRequestCache (object o, EventArgs args, AsyncCallback cb, object data)
@@ -105,9 +110,12 @@ namespace System.Web.Caching {
                        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;
                        } 
@@ -125,10 +133,24 @@ namespace System.Web.Caching {
                                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)