Question

I have a page that I've been using that pulls a lot of data for people to see. The data updates about every minute... So to decrease server load I cache the page for 60 seconds:

    '-----Set Cache
    Response.Cache.SetExpires(DateTime.Now.AddSeconds(60))
    Response.Cache.SetCacheability(HttpCacheability.Server)
    Response.Cache.SetValidUntilExpires(True)
    '---------------

That was working great... but now I added an asp.net Timer and set the interval to 30 seconds for testing.

I have a timestamp on the page and when the timer.tick event happens and updates the updatepanel, the timestamps are changing.

Protected Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
    updatePanel.Update()
End Sub

Prior to the timer, the timestamps would stay the same on a browser refresh because the cache. Now it appears they're updating on each tick event (eliminating the purpose of caching).

Even in 2 browsers side-by-side, the timestamps are updating on EVERY update by each browser...

So it appears that the timer loses the cache and defeats the purpose.

Does anyone know how to solve this issue? The page does not have any controls (buttons, dropdowns, etc) it just displays data in grids (multiple instances of user controls inserted programatically).

Était-ce utile?

La solution

What you've added - basically caches the GET request for the page. The POST (when the timer fires) typically isn't cached. I'd suggest that you not cache the actual page, but the results of your 'a lot of data'. Please take a look into HttpRuntime.Cache Should I use HttpRuntime.Cache?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top