What is difference between MemoryCache vs ObjectCache in .net 4.0?

前端 未结 3 2043
不思量自难忘°
不思量自难忘° 2021-02-02 05:35

What is difference between .NET framework 4.0 MemoryCache vs ObjectCache? Where to use which object?

3条回答
  •  鱼传尺愫
    2021-02-02 06:26

    From MSDN;

    The ObjectCache type is the primary type for the in-memory object cache. The built-in MemoryCache class derives from the ObjectCache class. The MemoryCache class is the only concrete object cache implementation in the .NET Framework 4 that derives from the ObjectCache class.

    public class MemoryCache : ObjectCache, 
        IEnumerable, IDisposable
    

    MemoryCache inherits from ObjectCache.

    You can get a reference to the default MemoryCache instance like this;

    public static ObjectCache cache = MemoryCache.Default;
    

提交回复
热议问题