Jawad Khan

Jawad's Lodge - The willingness to torture yourself before others is what makes a developer truly a unique breed.
posts - 45, comments - 150, trackbacks - 155

My Links

News

Archives

Post Categories

Image Galleries

How to Inavlidate User Control Cache Programatically....

Frequently you want to make sure that while Caching the User Control you have successfuly went through all the code paths in the code behind file. For e.g: you don't want to cache the User Control if there was an Error connecting to database that fills the DataGrif i.e. an empty resultset or worse an error is thown.

What you really want is to try to regenerate the output on next request i.e Invalidate the Cache for current request. Whidbey will not have this issue and you could progamitically control User Control cache as well. But as of Now there is no easy way to invalidate user Control Cache. So I came up with this solution

       Put a flag on the User Control code behind some thing like.

     bool AllWentWell = false;

     and when I have processed every thing and the control flow through
normally through all if conditions then at the end set this flag too:
         AllWentWell = true;

   Now at the very end of my User Control PreRender event I will set a
Dependency which will expire after a second if   AllWentWell is still
false .... That should do the trick ....

                private void Navig_PreRender(object sender, EventArgs e)
                {
                                       ...... Do what ever need to be
done ....
                                      ...... At the end
.................
                                     if ( !AllWentWell )
                                     {
                                           BasePartialCachingControl c
= Parent as BasePartialCachingControl;
                                          if (c != null) {
                                          c.Dependency = new
CacheDependency(on another data Cache Key that expires in a second );
                                     }
                                 }

Print | posted on Thursday, May 12, 2005 9:43 PM | Filed Under [ ASP.NET ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: