什么是.NET 4.0的MemoryCache区别VS ObjectCache? [英] what is difference between MemoryCache vs ObjectCache in .net 4.0?

查看:160
本文介绍了什么是.NET 4.0的MemoryCache区别VS ObjectCache?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是.NET 4.0的MemoryCache区别VS ObjectCache? 凡使用哪个对象?

what is difference between .net 4.0 MemoryCache vs ObjectCache? Where to use which object?

推荐答案

ObjectCache是​​演示你应该如何去建立一个缓存坚持谁写ObjectCache的人希望你遵守规则的抽象类。无法实例ObjectCache直接,因为它是抽象

ObjectCache is the abstract class that demonstrates how you should build a Cache that adheres to the rules the person who wrote ObjectCache wants you to obey. You cannot instantiate ObjectCache directly as it is abstract.

的MemoryCache是​​一个实际的实施 ObjectCache的。

MemoryCache is an actual implementation of ObjectCache.

从文档:

<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.objectcache.aspx">ObjectCache

再presents对象缓存,提供了基础的方法和   属性访问对象的缓存。

Represents an object cache and provides the base methods and properties for accessing the object cache.

<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx">MemoryCache

再presents实现在内存中缓存的类型。

Represents the type that implements an in-memory cache.

纵观声明的MemoryCache:

Looking at the declaration for MemoryCache:

public class MemoryCache : ObjectCache, 
    IEnumerable, IDisposable

我们可以看到,从的MemoryCache继承ObjectCache - 也就是说,它是一个使用内存作为存储对象的缓存 - 因此,这是的的实施的ObjectCache的

We can see that MemoryCache inherits from ObjectCache - that is, it's an cache for objects that uses Memory as its storage - this is therefore an implementation of ObjectCache.

您可以编写自己的;例如,DatabaseCache,这也可以从ObjectCache继承,而是会使用一个数据库作为后备存储。

You could write your own; for example, DatabaseCache, which could also inherit from ObjectCache but instead it would use a database as the backing storage.

对于日常使用,只要它满足你的需求,你会使用和消耗的MemoryCache。如果你想写你自己的,你可以继承ObjectCache和实施所需的方法和属性。然而,在现实中,有可能是没有什么实际利益这样做的微软已经做出一些其他的缓存解决方案可用,像许多其他供应商。

For everyday use, provided it met your needs, you would use and consume a MemoryCache. If you wanted to write your own, you could inherit from ObjectCache and implement the required methods and properties. However, in reality, there is probably little practical benefit to doing this as Microsoft already make several other caching solutions available, as do many other vendors.

这篇关于什么是.NET 4.0的MemoryCache区别VS ObjectCache?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆