문제

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?

도움이 되었습니까?

해결책

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")

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top