سؤال

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