Is System.Web.Caching or System.Runtime.Caching preferable for a .NET 4 web application

前端 未结 2 1445
半阙折子戏
半阙折子戏 2021-01-30 20:49

I am adding caching to an ASP.NET web application. This is .NET 4, so I can use the classes in the System.Runtime.Caching namespace (which, as I understand it, was added to pro

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 21:23

    Microsoft recommends using System.Runtime.Caching for all caching purposes. See this: http://msdn.microsoft.com/en-us/library/dd997357.aspx

    Although, I have come across a couple threads where people are having issues with the MemoryCache.Default instance. After a while, it stops working properly. Any item you add using the Add or Set method does not actually get added to the cache. I tried the same and was able to reproduce this issue with explicitly calling MemoryCache.Default.Dispose() method.

    Here are the links: MemoryCache Empty : Returns null after being set

    http://forums.asp.net/t/1736572.aspx/1

    My recommendation is to use the System.Web.Caching (HttpContext.Current.Cache)

    UPDATE:

    This issue has been fixed by MS. Check the accepted answer in the post below: Runtime Cache Issue Resolved

提交回复
热议问题