【问题标题】:WCF cache does not work when called from a mobile application从移动应用程序调用时,WCF 缓存不起作用
【发布时间】:2020-03-06 17:01:59
【问题描述】:

我已经使用以下代码实现了 WCF 缓存:

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>

当我使用浏览器调用 REST API 时,该解决方案可以正常工作。响应被缓存。但是,当我从移动应用程序调用 REST API 时,响应不会被缓存。我错过了什么吗?

【问题讨论】:

    标签: asp.net rest web-services wcf outputcache


    【解决方案1】:

    事实证明,出于某种原因,我不得不在 Web.config 中包含另一个参数,该参数在移动应用程序中使用/调用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-18
      • 2012-06-13
      • 2012-06-24
      • 2013-10-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      相关资源
      最近更新 更多