WCF缓存不工作 [英] WCF Cache Not Working

查看:159
本文介绍了WCF缓存不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的WCF服务缓存一些服务。我用WCF的Web HTTP服务微软缓存支持我的参考。我的服务器web.config文件是:

I want to cache some services in my WCF Service. I used Microsoft Caching Support for WCF Web HTTP Services as my reference. My server web.config file is:

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

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
        multipleSiteBindingsEnabled="true" />

我的解决办法是这样的(只包含2 Web项目):

My solution is like this (containing only 2 web projects.):

和我的客户code为(位于Default.aspx的):

And my client code is (located in Default.aspx):

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);
    }
}

Service是:

Service is:

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

只是返回当前日期时间。所以,我希望它回归的常数日期时间604800秒的时间间隔(如在web.config中声明)。但它会被更新,每次客户端调用它。

Simply returns current date time. So I hope it return's constant date time for "604800 seconds" interval (as declared in web.config). But it will be updated every time client call it.

推荐答案

我不是pretty肯定,但<一个href=\"http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute(v=vs.110).aspx\"相对=nofollow> WebGetAttribute 是RESTful服务。所以我觉得整个缓存将只对RESTful服务是工作。

I am not pretty sure but WebGetAttribute is for RESTful service. So I think the entire caching will be work only for RESTful services.

缓存另一种方式的http://pieterderycke.word$p$pss.com/2012/04/09/caching-in-wcf-services-part-1/.

这篇关于WCF缓存不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆