views:

257

answers:

1

I've a page that uses

<%@ outputcache duration="8640" varybyparam="*" %>

The goal is to cache it for up to 24 hours, but I want it to specifically expire at midnight. Anyone know the trick?

+1  A: 

You could calculate the number of seconds to midnight every time the page is loaded, then programatically set the duration using Response.Cache.SetExpires. I've never done it, but I don't see why it wouldn't work.

Obviously, this is midnight on the server, you probably have no idea what time of day it is on the client.

EDIT. Actually, looking at the defintion of SetExpires it takes a DateTime and not a duration, so you don't even need to calculate the number of seconds, just pass it whatever DateTime the next midnight is going to be.

Steve Haigh
Thanks. Yes, it is midnight on the server. That's when the data source gets changed.
Charles