Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

c# - Should I use HttpRuntime.Cache?

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

  1. HttpRuntime.Cache only provides severals methods and I think I'm able to implement these methods with Dictionary by myself.
  2. If HttpRuntime.Cache is much better than Dictionary, why some people would like to implement their own cache framework.
  3. How about MS Enterprise Cache Block?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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)If HttpRuntime.Cache is much better than Dictionary, why some people would like to implement their own cache framework.

People wouldn't want to do that.

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.

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...