Caching in WCF?

前端 未结 9 916
故里飘歌
故里飘歌 2020-11-29 01:50

I am building a WCF service. I need to store reference data in the cache which I will look up every time I receive input from the method... What is the right way to do this?

相关标签:
9条回答
  • 2020-11-29 02:18

    There are many ways you can do this. One fairly easy is to host the System.Web.Cache object yourself and use that to store the reference data. There's a good example of that here: http://kjellsj.blogspot.com/2007/11/wcf-caching-claims-using.html

    0 讨论(0)
  • 2020-11-29 02:19

    Rather than expiring the cache data every so often, you can actually just make sure to invalidate the cache whenever the underlying data you are caching changes.

    See this example from info Q http://www.infoq.com/news/2011/04/Attribute-Caching

    [Cache.Cacheable("UserTransactionCache")]
    public DataTable GetAllTransactionsForUser(int userId)
    {
        return new DataProvider().GetAllTransactionsForUser(userId);
    }
    
    [Cache.TriggerInvalidation("UserTransactionCache")]
    public void DeleteAllTransactionsForUser(int userId)
    {
     ...
    }
    
    0 讨论(0)
  • 2020-11-29 02:20

    this is a good article: http://cascadeofinsights.com/post/1410736927/introducing-attribute-based-caching

    0 讨论(0)
  • 2020-11-29 02:22

    You could take a look at Velocity. This is Microsoft's distributed in-memory caching framework. But this may be a little bit too beta...

    0 讨论(0)
  • 2020-11-29 02:23

    If you are using .NET 4, the recommended way is to use MemoryCache

    0 讨论(0)
  • 2020-11-29 02:23

    The WCF REST Starter Kit has caching, here is an article about using it... with sample code.

    http://weblogs.asp.net/gsusx/archive/2008/10/29/adding-caching-to-wcf-restful-services-using-the-rest-starter-kit.aspx

    0 讨论(0)
提交回复
热议问题