Click to See Complete Forum and Search --> : Problem with removing a user control from the Cache


Kalyan
06-12-2007, 10:33 AM
Hi

I have user control in my application that is used in many of the pages.. it is constant for all the pages..but only changes when the user selects a particular value in a dropdown and clicks on a button... so basically I could cache the control and refresh it in the cache when the user clicks on the button...I read somewhere that you can create a dependency on the wrapper class for some cache key and delete the key when you want to refresh the control in the cache.. so I wrote a small application to try out the idea...

default.aspx

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If (Cache.Item("CacheRemovalKey") Is Nothing) Then
Cache.Insert("CacheRemovalKey", "Key", Nothing, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration) Dim pcc As PartialCachingControl = CType(LoadControl("UserControlEx.ascx"), PartialCachingControl) Dim DependentKeyArray As String() = {"CacheRemovalKey"} pcc.Dependency = New System.Web.Caching.CacheDependency(Nothing, DependentKeyArray)
End If

End Sub


Protected Sub btnChange_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnChange.Click

Cache.Remove("CacheRemovalKey")

End Sub



UserControl.ascx.vb


Partial Class UserControlEx Inherits System.Web.UI.UserControl

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtDateTime.Text = Date.Now
End Sub

End Class



However the user control is not refreshing when I click on the button.... am really having difficult time trying to solve this.. could certainly use some help from you guys....

Thanks
:)

Kalyan
06-14-2007, 02:45 AM
no progress for me still.. anybody out there with any ideas on how to
make this work.. am I missing something?
any alternative solution?

Phil Weber
06-16-2007, 05:06 PM
Unless the HTML for this control is very large, I would forget trying to cache it. It seems like more trouble than it's worth.