views:

46

answers:

2

Hi,

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!

+1  A: 

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
I thought about it, but I'm not sure that it's the only possible / best solution in this case.
Adam
@Adam, what control does? Maybe you can move some parts of it out of control and Cache only needed part?
eugeneK
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
then i see no other way then either to use my advice or to redesign control itself.
eugeneK
I think it's the only option as for now.
Adam
A: 

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 R