D.R.
D.R.

Reputation: 21224

SQL cache dependency: Poll specific time of day

We want to improve the performance of our WCF service by introducing output caching.

For each different URL (varyByParam="none" varyByCustom="RawUrl") we want to cache the result as long as the database table FooBar has not changed.

However, we want to check such a change only once per day (6:20 AM). If the table changes during the day, we do not want the cache to be cleared until the next day 6:20 AM.

We know that this can result in unconsistent outputs, however, in our application scenario this is not a problem.

How to tell the outputCache to check for changes only at 6:20 AM each day?

Upvotes: 0

Views: 225

Answers (2)

Tim P.
Tim P.

Reputation: 2942

Set your IIS Application Pool to reset at 6:20am every day, instead of making this a code solution.

Some browsers will ignore the HTTP Cache headers as suggested above.

Upvotes: 1

Alexander Manekovskiy
Alexander Manekovskiy

Reputation: 3203

I think you can use Response.Cache.SetExpires method as descrived in How to: Cache Versions of a Page Using Parameters.

The code will be something like:

var tomorrow = DateTime.Today.AddDays(1);
Response.Cache.SetExpires(new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, 6, 20, 0, DateTimeKind.Local)
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
Response.Cache.SetVaryByCustom("RawUrl")

Upvotes: 1

Related Questions