asp.netrestweb-serviceswcfoutputcache

WCF cache does not work when called from a mobile application


I've implemented WCF caching using the below code:

iService.vb

<OperationContract()>
<AspNetCacheProfile("CacheFor60Seconds")>
<WebGet(RequestFormat:=WebMessageFormat.Json, UriTemplate:="some-url?id={id}", BodyStyle:=WebMessageBodyStyle.Bare, ResponseFormat:=WebMessageFormat.Json)>


Web.Config

<system.web>
    <caching>
      <outputCache enableOutputCache="true"></outputCache>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="CacheFor60Seconds" duration="60" varyByParam="id"/>
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
</system.web>

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="0" multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>
</system.serviceModel>

The solution works properly when I call the REST API using the browser. The response gets cached. However, when I call the REST API from a mobile application, the response is not cached. Did I miss anything here?


Solution

  • It turned out that for some reason, I had to include the other parameter in the Web.config which was used/called in/from the mobile mobile application:

    <add name="CacheFor60Seconds" duration="60" varyByParam="id;param2"/>