7

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I haven't tried this, but my understanding of Output Caching is that it only related to keeping results in memory, and doesn't affect the HTTP cache control headers.
@BrianReischl OutputCacheProfiles have a location attribute that can be defined as Server or Client. When set to Client a response contains HTTP Headers matching the OutputCacheProfile's definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.