WCF AJAX Responses Cached by IE

This problem seems obvious to me AFTER the fact I implemented it. Since REST calls are just HTTP GET Requests (at least the ones I’m talking about) of course IE would cache the response.

This can definitely make for interesting troubleshooting when you are expecting a different result set for the same request :)

To tell the browser not to cache your WebGet responses you will need to create an OutputCacheProfile that specifies no caching and then assign that profile to each method of your service.

The following example will go in the <system.web> section of your config file.

<caching>
   <outputCacheSettings>
     <outputCacheProfiles>
 <add name=”DoNotCache” duration=”0″ noStore=”true” varyByParam=”none”/>
     </outputCacheProfiles>
   </outputCacheSettings>
</caching>

For each [WebGet] method you should specify the DoNotCache profile using the AspNetCacheProfile attribute. Below is the example of the method that was causing problems for me. You could add a new “home” favorite but when you retrieved them later you recieved a cached copy (minus the favorite you just added).

[WebGet]
[OperationContract]
[AspNetCacheProfile("DoNotCache")]
public WSProperty[] GetFavorites(String username)

Shameless plug: If you are looking for Frisco Real Estate or McKinney Homes for Sale  stop by our site http://www.bwhometeam.com.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s