views:

529

answers:

2

I am using the Asp.net OutputCache on a page containing a usercontrol that in certain circumstances when the usercontrol is edited i want to be able to expire the page cache and reload the page with fresh data.

Is there any way i can do this from within the usercontrol?

If not, what are some other methods of caching the page that will allow me to edit in this way.

----------- EDIT -----------

After some more research I found a method that seems to work well.

Dim cachekey As String = String.Format("Calendar-{0}", calendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
Response.AddCacheItemDependency(cachekey)

that will add a dependency to the page cache object, then to expire I do this:

Dim cachekey as string = String.Format("Calendar-{0}", CalendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)

Now as long as the dependency cachekey is known a page can be expired.

+1  A: 

Hi,

You could try this:

private void RemoveButton_Click(object sender, System.EventArgs e)
{
    HttpResponse.RemoveOutputCacheItem("/caching/CacheForever.aspx");
}

From: http://aspalliance.com/668

Thanks.

afgallo
yeah that seems to be the only example out there, but it doesnt take into account the VaryByParams, so if i expire that page i think there'd still be data in the cache for the same page with different query strings.
John Boker
A: 

After some more research I found a method that seems to work well.

Dim cachekey As String = String.Format("Calendar-{0}", calendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)
Response.AddCacheItemDependency(cachekey)

that will add a dependency to the page cache object, then to expire I do this:

Dim cachekey as string = String.Format("Calendar-{0}", CalendarID)
HttpContext.Current.Cache.Insert(cachekey, DateTime.Now, Nothing, System.DateTime.MaxValue, System.TimeSpan.Zero, System.Web.Caching.CacheItemPriority.NotRemovable, Nothing)

Now as long as the dependency cachekey is known a page can be expired.

John Boker