System.Runtime.Caching.MemoryCache vs HttpRuntime.Cache - are there any differences?

前端 未结 4 1777
执念已碎
执念已碎 2020-12-07 14:24

I\'m wondering if there are any differences between MemoryCache and HttpRuntime.Cache, which one is preferred in ASP.NET MVC projects?

As f

4条回答
  •  时光取名叫无心
    2020-12-07 14:34

    MemoryCache.Default can also serve as a "bridge" if you're migrating a classic ASP.NET MVC app to ASP.NET Core, because there's no "System.Web.Caching" and "HttpRuntime" in Core.

    I also wrote a small benchmark to store a bool item 20000 times (and another benchmark to retrieve it) and MemoryCache seems to be two times slower (27ms vs 13ms - that's total for all 20k iterations) but they're both super-fast and this can probably be ignored.

提交回复
热议问题