Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

CacheItemRemovedCallback does not update Cache object properly

Avatar of SystemExpert
SystemExpertFlag for United States of America asked on
ASP.NET
5 Comments1 Solution837 ViewsLast Modified:
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