C# WCF缓存不工作
我想在我的WCF服务中缓存一些服务。我用微软作为我的参考。我的服务器web.config文件是: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
<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;
}