Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF缓存不工作_C#_Asp.net_Asp.net Mvc_Wcf_Caching - Fatal编程技术网

C# WCF缓存不工作

C# WCF缓存不工作,c#,asp.net,asp.net-mvc,wcf,caching,C#,Asp.net,Asp.net Mvc,Wcf,Caching,我想在我的WCF服务中缓存一些服务。我用微软作为我的参考。我的服务器web.config文件是: <caching> <outputCache enableOutputCache="true" /> <outputCacheSettings> <outputCacheProfiles> <add name="GetCurrentDateTime" location="Server" durati

我想在我的WCF服务中缓存一些服务。我用微软作为我的参考。我的服务器web.config文件是:

  <caching>
    <outputCache enableOutputCache="true" />
    <outputCacheSettings>
      <outputCacheProfiles>
        <add name="GetCurrentDateTime" location="Server" duration="604800" varyByParam="offset; lang; categorytype" enabled="true" />
      </outputCacheProfiles>
    </outputCacheSettings>
  </caching>
服务是:

    [WebGet]
    [AspNetCacheProfile("GetCurrentDateTime")]
    public string GetCurrentDateTime()
    {
        var datetime = DateTime.Now.ToString();
        return datetime;
    }
只返回当前日期时间。所以我希望它返回“604800秒”间隔的恒定日期时间(如web.config中声明的)。但每次客户端调用它时,它都会更新。

我不太确定,但它是用于RESTful服务的。因此,我认为整个缓存只适用于RESTful服务

另一种缓存方式如中所述

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var client = new Test_Services.TestServicesClient();

        var dateTime = client.GetCurrentDateTime();
        Response.Write(dateTime);
    }
}
    [WebGet]
    [AspNetCacheProfile("GetCurrentDateTime")]
    public string GetCurrentDateTime()
    {
        var datetime = DateTime.Now.ToString();
        return datetime;
    }