[Asp .Net Page output caching] invalidate subset of pages on demand only

fishermagenta

New Member
Hello,

I am writing an engine for a forum. Now I have stumbled upon some problems with caching. I have a board view with multiple threads printed and each
one has a first few replies added. Now I decided I want to have caching not based on timeout but on custom action. When a user uploads some reply, only
then should the page expire from cache. It is also desirable to expire only those versions of pages that need to be expred (based on query string parameters).

let's say I have this situation:

so http://forum/index.aspx?page=1 cached
so http://forum/index.aspx?page=2 cached
so http://forum/index.aspx?page=3 cached
so http://forum/index.aspx?page=4 cached -> reply happes
so http://forum/index.aspx?page=5 cached
so http://forum/index.aspx?page=6 cached

.. pages 1 - 4 must expire from cache. The rest should stay in cache. Also I do not want any of the pages to expire from the cache before this action
for whatever reason this could happen. Please help me with this.

for now I have written in page load of index.aspx this:

1) in global.asax, Application_Start:
HttpRuntime.Cache.Insert("all", DateTime.Now);

2) and in my index.aspx page load event this:

Response.AddCacheItemDependency("all");
Response.Cache.SetCacheability(HttpCacheability.Se rverAndNoCache);
Response.Cache.SetExpires(DateTime.Now.AddMinutes( 5));
Response.Cache.SetValidUntilExpires(true);
//Response.Cache.VaryByParams["page"] = true;

3) then if I want to reset all pages dependend on key all, I call index.aspx with query string parameter ccreset and again
in global.asax Application_BeginRequest I check for this query string parameter and modify key all to invalidate cache like this:
HttpRuntime.Cache.Remove("all");



PROBLEMS
________


A) Even without trying to invalidate my cache, page output caching occurs only if I do not specify VaryByParams. As fast as I add this line of code:
Response.Cache.VaryByParams["page"] = true;
caching stops. I print a timestamp on the page to see this. I do not understand this. Problem is exactly the same if I use the declarative syntax inside
aspx page.

B) Let's say I forget about the VaryByParams, caching works out of the box, time stamps printed on my page confirm this. But, even when I modify the
"all" key in my cache hoping to initiate cache invalidation nothing happens. All pages remain in the cache as nothing happened. Why is that?


QUESTION
_________

I would like to understand why B) happens and also what is up with A). But please, if I should be doing this thigs some other way feel free to skip
answering me my first two questions and just explaing to me what is the easiest and most straight forward way to achieve what I want.

Thank you for your replies in advance
Andrej
 
Top