SystemExpert
asked on
CacheItemRemovedCallback does not update Cache object properly
Hi,
I have used Asp.net ,Vb.net (1.1)
I am not able to refresh my cache object every 10 sec
It happens only if I refresh the page
And it does not call automatically after 10 sec.
--------------Code--In ---Global.asax------------ ----
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim onRemove As CacheItemRemovedCallback = New CacheItemRemovedCallback(A ddressOf RefreshCache)
RefreshCache("Employees", Nothing, CacheItemRemovedReason.Exp ired)
End Sub
Shared Sub RefreshCache(ByVal key As String, ByVal item As Object, ByVal reason As System.Web.Caching.CacheIt emRemovedR eason)
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT EmployeeID, lastname, firstname FROM Employees", "Data Source=................con nection String.................... ...")
Dim con As New SqlClient.SqlConnection
Dim ds As New DataSet
adapter.Fill(ds, "Employees")
Dim onRemove As CacheItemRemovedCallback = New CacheItemRemovedCallback(A ddressOf RefreshCache)
System.Web.HttpContext.Cur rent.Cache .Remove("E mployees")
HttpContext.Current.Cache. Add("Emplo yees", ds, Nothing, Date.Now.AddSeconds(10), TimeSpan.Zero, CacheItemPriority.High, onRemove)
End Sub
-------End of Code-----------
Thanks & Regards
I have used Asp.net ,Vb.net (1.1)
I am not able to refresh my cache object every 10 sec
It happens only if I refresh the page
And it does not call automatically after 10 sec.
--------------Code--In ---Global.asax------------
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim onRemove As CacheItemRemovedCallback = New CacheItemRemovedCallback(A
RefreshCache("Employees", Nothing, CacheItemRemovedReason.Exp
End Sub
Shared Sub RefreshCache(ByVal key As String, ByVal item As Object, ByVal reason As System.Web.Caching.CacheIt
Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT EmployeeID, lastname, firstname FROM Employees", "Data Source=................con
Dim con As New SqlClient.SqlConnection
Dim ds As New DataSet
adapter.Fill(ds, "Employees")
Dim onRemove As CacheItemRemovedCallback = New CacheItemRemovedCallback(A
System.Web.HttpContext.Cur
HttpContext.Current.Cache.
End Sub
-------End of Code-----------
Thanks & Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try this on for size:
ASP.NET Crash: Bad CacheItemRemovedCallback - Part II
http://blogs.msdn.com/tess/archive/2006/11/27/asp-net-crash-bad-cacheitemremovedcallback-part-ii.aspx
<Quote>The morale of the story is, don't use the CacheItemRemovedCallback to add a new copy of the same cache item. Instead use sliding expiration, and instead add the cached item when you try to access the cached item and this item is null.</Quote>
Bob
ASP.NET Crash: Bad CacheItemRemovedCallback - Part II
http://blogs.msdn.com/tess/archive/2006/11/27/asp-net-crash-bad-cacheitemremovedcallback-part-ii.aspx
<Quote>The morale of the story is, don't use the CacheItemRemovedCallback to add a new copy of the same cache item. Instead use sliding expiration, and instead add the cached item when you try to access the cached item and this item is null.</Quote>
Bob
ASKER
Thanks Bob
Last I used Thredpool
Thanks
Last I used Thredpool
Thanks
Did that work?
Bob
Bob
ASKER
Bob,
I just add it because I can call it from my .aspx page for Testing purpose
later on I will put this method in Data Layer
That's not the problem
Thanks