Caching in WCF?

前端 未结 9 957
故里飘歌
故里飘歌 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: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)
    {
     ...
    }
    

提交回复
热议问题