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

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

问题描述

我是 asp.net 的初学者,有一些关于缓存的问题:

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

  1. HttpRuntime.Cache 只提供了几种方法,我想我可以自己用 Dictionary 实现这些方法.
  2. 如果 HttpRuntime.Cache 比 Dictionary 好很多,为什么有些人想要实现自己的缓存框架.
  3. 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 不仅仅是一个简单的字典.它提供线程安全和缓存过期策略.它提供了使用自定义实现的可能性,并从分布式缓存中受益,这对网络农场很有帮助.使用字典实现这一点可能需要大量工作,您可能不想冒险,因为您基本上是在重新发明轮子,即使重新发明轮子不会打扰您,正确完成的机会也很渺茫.

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.

所以回答你的问题:我应该使用 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天全站免登陆