Last post Feb 16, 2009 01:43 PM by randallt
Feb 16, 2009 10:03 AM|LeeTheGreek|LINK
I am using a customised version of the REST starter kit which includes Damian Mehers changes to dynamically retrieve data in either xml or json. Everything works peachy, except when i decorate my OperationContract with "[WebCache(CacheProfileName = "CacheFor1Min")]".
If I request my data in xml (since its now become cached), it will always retrieve the cached data in xml, even when i request the data in json. Anyone know of a solution?
Feb 16, 2009 01:43 PM|randallt|LINK
It is not the data from your service that is cached but the response message that goes on the wire. The ASP.NET output cache is closer to the wire than WCF, and the ASP.NET output cache knows nothing about the types within your service. Therefore, what
is being cached is the XML representation of your data.
However, there is a way to solve your problem. The dynamic formatting that Mahers provides appears to be based on the Accept header of the request message. You can configure the ASP.NET output cache to cache different versions of your operation's response
messages based on the request message Accept header. Simple set the VaryByHeader property to "Accept". You can either set the property of the WebCache attribute, or simple add the attribute to your output cache profile in your web.config.
4 <add name="CacheFor1Min" duration="60" enabled="true"