3

I solved most of the issues I had with caching. But still there is one thing. I have a UserControl for which I use output caching. Just like this:

<%@ OutputCache Duration="1200" VaryByParam="none" %> 

However, as you can see, the control is recreated every 12 minutes, because it takes from 5 to 10 seconds to generate it.

Now, the default behavious for ASP.NET is to create the control when user enter the page and keep it in cache for 12 minutes. Then when after another 5 minutes user enters the page the control is created again.

Is there a way to force ASP.NET to recreate the control after the 12 minutes cache expires? No matter on the next user visit?

Or even a perfect solution: recreate control in background after lets say 11 minutes 50 seconds, and than just replace the actual one with the new one after 12 minutes?

Thanks for help!

Adam
  • 756
  • 4
  • 10
  • 23
  • 1
    Isn't that a waste? If no user comes to page with control why to reload it? anyway what control does, is there DB calls on it? – eugeneK Jul 06 '10 at 07:24
  • Yes it calls DB, but the DB communication is cached by the Cache Mechanism. The control logic itself take so much time. And it's no way I can reduce this logic any more. – Adam Jul 06 '10 at 09:06

2 Answers2

1

Use Windows Scheduled Tasks to enter this page every 12 minutes because ASP.NET works with triggers only. Trigger can be either Ajax that requests other page every 12 minutes or next user that comes to your webpage.

eugeneK
  • 10,750
  • 19
  • 66
  • 101
  • I thought about it, but I'm not sure that it's the only possible / best solution in this case. – Adam Jul 06 '10 at 09:07
  • @Adam, what control does? Maybe you can move some parts of it out of control and Cache only needed part? – eugeneK Jul 06 '10 at 09:21
  • Unfotunately the control creates a lot of controls (labels, divs) and adds it into other controls within the control. And I can not cache controls outside a control - because adding cached HTML by using the Controls.Add() method - will end with an exception. – Adam Jul 06 '10 at 09:25
  • then i see no other way then either to use my advice or to redesign control itself. – eugeneK Jul 06 '10 at 10:09
  • I think it's the only option as for now. – Adam Jul 06 '10 at 10:30
0

I'm not sure, but it sounds like you want your control to be updated asynchronously at intervals while the user is viewing the page?

If so, you'd need to use Ajax. For example, the Timer control allows UpdatePanels to be asynchronously updated at set intervals.

By the way, the duration you have in your example is actually 20 minutes.

Joe Ratzer
  • 18,176
  • 3
  • 37
  • 51