Link to home
Start Free TrialLog in
Avatar of SystemExpert
SystemExpertFlag for United States of America

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(AddressOf RefreshCache)
        RefreshCache("Employees", Nothing, CacheItemRemovedReason.Expired)

    End Sub
 
    Shared Sub RefreshCache(ByVal key As String, ByVal item As Object, ByVal reason As System.Web.Caching.CacheItemRemovedReason)

        Dim adapter As SqlDataAdapter = New SqlDataAdapter("SELECT EmployeeID, lastname, firstname FROM Employees", "Data Source=................connection String.......................")
        Dim con As New SqlClient.SqlConnection
        Dim ds As New DataSet
        adapter.Fill(ds, "Employees")
        Dim onRemove As CacheItemRemovedCallback = New CacheItemRemovedCallback(AddressOf RefreshCache)

         System.Web.HttpContext.Current.Cache.Remove("Employees")
        HttpContext.Current.Cache.Add("Employees", ds, Nothing, Date.Now.AddSeconds(10), TimeSpan.Zero, CacheItemPriority.High, onRemove)
    End Sub

-------End of Code-----------
Thanks & Regards
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SystemExpert

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

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
Thanks Bob

Last I used Thredpool

Thanks
Did that work?

Bob