我应该使用HttpRuntime.Cache吗? [英] Should I use HttpRuntime.Cache?

查看:106
本文介绍了我应该使用HttpRuntime.Cache吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是asp.net的初学者,对缓存有一些疑问:

I'm a beginner in asp.net, and have a few question of Cache:


  1. HttpRuntime.Cache仅提供了几种方法

  2. 如果HttpRuntime.Cache比Dictionary更好,为什么有些人希望实现自己的缓存框架。
  3. / li>
  4. MS Enterprise Cache Block怎么样?


推荐答案


HttpRuntime.Cache仅提供了几种方法,我认为我能够
自己通过Dictionary实现这些方法。

HttpRuntime.Cache only provides severals methods and I think I'm able to implement these methods with Dictionary by myself.

您认为错了。 HttpRuntime.Cache不仅仅是一个简单的字典。它提供线程安全和缓存过期策略。它提供了使用自定义实现的可能性,并受益于分布式缓存,这对Web场很有帮助。用字典来实现它可能是您不愿冒险的工作,因为您将基本上是在重新发明轮子,即使重新发明轮子不会打扰您,正确实现它的机会也很小。

You think wrong. HttpRuntime.Cache is much more than a simple dictionary. It offers thread-safety and cache expiration policies. It provides possibilities of using custom implementation and benefit from distributed caching which is helpful in web farms. Implementing this with dictionaries could be lots of work that you probably don't want to venture into as you will be basically reinventing the wheels and even if reinventing wheels doesn't bother you chances for getting it right are slim.


2)如果HttpRuntime.Cache比Dictionary更好,为什么有些人
想要实现自己的缓存框架。

2)If HttpRuntime.Cache is much better than Dictionary, why some people would like to implement their own cache framework.

人们不想这样做。


3 )MS Enterprise Cache Block怎么样?

3) How about MS Enterprise Cache Block?

那是沉重的大炮,当您需要简单的缓存时,并不一定需要这样做

That's heavy artillery which is not always necessary when you need simple caching which could be achieved with what the framework already provides you out of the box.

备注:在.NET 4.0中,您应该使用新的System.Runtime.Caching 名称空间,而不是 HttpRuntime.Cache

Remark: In .NET 4.0 you should use the new System.Runtime.Caching namespace instead of HttpRuntime.Cache.

所以o回答您的问题:我应该使用HttpRuntime.Cache

So to answer your question: Should I use HttpRuntime.Cache

是的,除非您使用的是.NET 4.0,情况下,您应该使用新的 System.Runtime.Caching 命名空间中的类。

Yes, unless you are using .NET 4.0 in which case you should use classes from the new System.Runtime.Caching namespace.

这篇关于我应该使用HttpRuntime.Cache吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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