Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SOS....OutputCaching Invalidation

1 view
Skip to first unread message

erasor

unread,
Apr 3, 2003, 8:45:12 AM4/3/03
to
Hi all,
I would be extremely glad if someone can provide a solution for
this.....
I have a data intensive web application...So usage of caching is a
must for improving preformance for me...So i have split the Pages into
different usercontrols...since parts of the page have to be completely
dynamic....
I have already implemented datacaching whereever it was feasible..so
now my database queries are optimized(minimized)

...but i need to improve the application furthur..
...so i HAVE to outputcache a few of the more static controls...here
my voes start....
I am aware of the outputcache directive....setting varybyparams etc...
but i find it very restricted for my application... suppose i have a
control which shows a few links ....the no: of links to show is
decided on the basis of a preference setting in the database...so as
long as that preference is not modified i can just outputcache the
control... but once it is changed..i want to IMMEDIATELY invalidate
that usercontrol cache....
so that a user who is using my app...does not have to see the page
with a ui preference that has been modified according to whatever
policies decide these...

as far as i understand...and what replies i have got from MS
support..there are
is "no programmatic API to invalidate user control output caching--Rob
Howard(MS asp.net team)".....A time based expiry is not a solution for
me....
So is there any way to do this....
1)Is there any way by which i can obtain the usercontrol output...and
cache it with a key based dependency...instead of letting asp.net do
it ...cos i dont have any control on it programmatically..?
OR
2)Is there any way by which i CAN invalidate the cached output...by
someother dependency mechanism....

...CAN ANYONE DO THIS....
3)or atleast can someone enlighten me on how MS has implemented the
key based dependency on the Cached page output(WHY THE HELL HAVE THEY
NOT PROVIDED THE SAME WITH THE CACHED USER CONTOL OUTPUT)...so that i
can attempt to do something like that...

...one interesting thing....user controls in which i set a output
cache will get compiled into a partialcachingcontrol... this class has
a property...cacheditemdependency....but i dont find any way in which
i can access this property...?(any ideas.)

PLLLLLZZZZZ...help
RAZORRASU

James Musson [MSFT]

unread,
Apr 15, 2003, 4:28:30 AM4/15/03
to
As far as I am aware there is no easy way to do this at the moment. What
you could do, though, is override the Render method of your UserControl and
put the caching logic in there yourself. It is not quite as neat or fast as
the built in mechanism because there is still always going to be some
control processing involved, but at least you don't actually have to process
the control tree and generate the html each time. You do get more control
with this method because you are adding the html into the cache yourself and
hence have access to dependencies etc.

I guess it would probably look something like this:

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
String controlHtml = (String)Cache["testControlHtml"];
if( controlHtml==null )
{
StringWriter sw = new StringWriter();
HtmlTextWriter newWriter = new HtmlTextWriter( sw );
base.Render( newWriter );
controlHtml = sw.ToString() + "<br><br>Generated at: " +
DateTime.Now.ToString();
Cache.Insert( "testControlHtml", controlHtml, null,
DateTime.Now.AddSeconds( 5 ),
System.Web.Caching.Cache.NoSlidingExpiration );
}
writer.Write( controlHtml );
}

...without error handling or thread synchronisation.

Hope this helps

Regards

James.
--
This posting is provided "AS IS" with no warranties, and confers no rights.


"erasor" <razo...@yahoo.com> wrote in message
news:8df61cf2.03040...@posting.google.com...

erasor

unread,
Apr 16, 2003, 10:36:31 AM4/16/03
to
thnx James....
that was a really good idea.. ill try it out..
in the meantime i found a way to do it... seems ok (functionally)
...but im not aware of any other problems with the method..

this is what i did...

put an @outputcache directive in the usercontrol...
put a place holder in the aspx page..
did not drop the control on to the page..

on page_load of the aspx..
i did..

partialcachingcontrol
pc=(PartialCachingControl)LoadControl("CachedUserControl.ascx");
pc.Dependency=new CacheDependency(null,new string[]{MySettings});
PlaceHolder.Controls.Add(logo);
...

this works...even the invalidation part...i ran a few stress test
using this method but i was not able to conclusively decide whether
this is a good way of doing it performance wise....
any suggestions..any obvious problems using this method...especially
when the number of users accessing the page increases ?

thnx once more...will try out ur sugg...
erasor...

erasor

unread,
Apr 16, 2003, 10:39:41 AM4/16/03
to
hi,
sorry .. a clarification

placeholder.Controls.Add(logo);
..please read as...

placeholder.Controls.Add(pc);
erasor..

James Musson [MSFT]

unread,
Apr 17, 2003, 5:40:22 AM4/17/03
to
If this works then I don't foresee any major problems with it. As for
performance, it is probably going to be as good as any other method of
achieving the same thing (and of course most likely better than not caching
at all). I guess the only real drawbacks are a lack of design time support
(as the type of control is not available at that point) and the fact that
you can only add dependency information, not actually affect the cache
duration etc.

Regards

James.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


"erasor" <razo...@yahoo.com> wrote in message

news:8df61cf2.03041...@posting.google.com...

0 new messages