【发布时间】:2019-08-13 17:27:51
【问题描述】:
Somanyexamples 在.NET (including the official docs) 中使用内存缓存实例化它:
private readonly ObjectCache memoryCache = MemoryCache.Default;
有什么理由更喜欢这个:
private readonly MemoryCache memoryCache = MemoryCache.Default;
【问题讨论】:
-
正如docs 所说,“MemoryCache 类是抽象 ObjectCache 类的具体实现。”
-
@stuartd 那部分是有道理的。我的困惑是为什么在你的类型声明中使用抽象类而不是具体类。
-
我怀疑人们会这样做,因为这就是文档示例中的内容。
标签: c# .net memorycache objectcache