I'm working on an HTTP REST service implemented on WCF. I'd like to set the HTTP cache control headers for my operations appropriately.
I've seen a few examples that involve using the WebOperationContext.Current.OutgoingResponse
to modify the headers in each method. But let's be honest, that's a pain in the butt, especially since nearly all of my operations are going to use the same cache control policy (no-cache).
I'm thinking there must be an elegant way to set this. Perhaps a combination of a ServiceBehavior to set a service-level default, and OperationBehaviors to override that for certain operations? Or maybe there's some better way to do this?
WCF services respect the outputCache setting in the Web.Config. Additionally you can specify OutputCacheProfiles which are also defined in the Web.config and then specify which OutputCacheProfle to use at the method level with decorators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With