System.Web.Caching 与企业库缓存块 [英] System.Web.Caching vs. Enterprise Library Caching Block

查看:22
本文介绍了System.Web.Caching 与企业库缓存块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于将在 Web 应用程序和富客户端应用程序中使用的 .NET 组件,似乎有两个明显的缓存选项:System.Web.Caching 或 Ent.自由.缓存块.

For a .NET component that will be used in both web applications and rich client applications, there seem to be two obvious options for caching: System.Web.Caching or the Ent. Lib. Caching Block.

  • 你用什么?
  • 为什么?

在网络应用程序之外使用是否安全?我看到了混合的信息,但我认为答案可能有点不真实.

Is this safe to use outside of web apps? I've seen mixed information, but I think the answer is maybe-kind-of-not-really.

  • a KB article warning against 1.0 and 1.1 non web app use
  • The 2.0 page has a comment that indicates it's OK: http://msdn.microsoft.com/en-us/library/system.web.caching.cache(VS.80).aspx
  • Scott Hanselman is creeped out by the notion
  • The 3.5 page includes a warning against such use
  • Rob Howard encouraged use outside of web apps

我不希望使用它的亮点之一,SqlCacheDependency,但是增加了CacheItemUpdateCallback 在 .NET 3.5 中似乎是一件非常好的事情.

I don't expect to use one of its highlights, SqlCacheDependency, but the addition of CacheItemUpdateCallback in .NET 3.5 seems like a Really Good Thing.

  • 其他块已在使用中,因此依赖项已存在
  • 缓存持久化不是必需的;重新启动时重新生成缓存是可以的

某些缓存项应该始终可用,但会定期刷新.对于这些项目,在删除项目后 获得回调不是很方便.看起来客户端只需要休眠和轮询,直到缓存项被重新填充.

Some cache items should always be available, but be refreshed periodically. For these items, getting a callback after an item has been removed is not very convenient. It looks like a client will have to just sleep and poll until the cache item is repopulated.

不需要分布式缓存有什么优点和缺点?

What are the pros and cons when you don't need a distributed cache?

推荐答案

这些是我考虑缓存主题的项目:

These are the items that I consider for the topic of Caching:

MemCached Win32速度.net 缓存企业库缓存应用程序块

MemCached Win32 Velocity .net Cache Enterprise Library Caching Application Block

MemCached Win32: 直到最近我一直在使用 MemCached Win32.这类似于 Web 场(许多服务器为高可用性提供相同的内容),但它是一个缓存场.这意味着如果您没有足够的资源来扩大规模,您可以最初将它安装在您的 Web 服务器上.然后,随着您的发展,您可以水平扩展(更多服务器)或垂直扩展(更多硬件).这是从原始 MemCached 移植到 Windows 上的产品.该产品已广泛用于高流量站点.http://lineofthought.com/tools/memcached

MemCached Win32: Up until recently I have used MemCached Win32. This is a akin to a web farm (many servers serving the same content for high availability) but it is a cache farm. This means that you can install it locally on your web server initially if you don't have the resources to go bigger. Then as you go down the road you can scale horizontally (more servers) or vertically (more hardware). This is a product that was ported from the original MemCached to work on Windows. This product has been used extensively in very high traffic sites. http://lineofthought.com/tools/memcached

Velocity:这是微软对 MemCached 等产品的回应.MemCached 已经出来一段时间了,Velocity 处于 CTP 模式.我必须说,从我到目前为止所读到的内容来看,这款产品一经推出肯定会引起我的注意.但我无法让自己在零记录的 CTP 产品上运行大型生产项目.我已经开始玩它了,因为一旦它获得动力,MemCached 甚至无法与那些锁定在 Windows 世界中的人相比!http://blogs.msdn.com/velocity/

Velocity: This is Microsofts answer to products such as MemCached. MemCached has been out for quite some time, Velocity is in CTP mode. I must say that from what I have read so far this product will certainly turn my head once it is out. But I can't bring myself to run big production projects on a CTP product with zero track record. I have started playing with it though as once it gains momentum MemCached won't even compare for those locked in the windows world! http://blogs.msdn.com/velocity/

.NET 缓存:没有理由打折标准的 .NET 缓存.它是内置的,可以免费使用,无需(主要)设置.它通过提供将项目存储在本地内存、单一状态服务器或中央数据库中的机制来提供灵活性.当您需要多个状态服务器(内存缓存)并且不想使用慢速数据库来保存缓存时,Velocity 就会介入.

.NET Cache: There is no reason to discount the standard .NET Cache. It is built in and ready to use for free and with no (major) set up required. It offers flexibility by way of offering mechanisms for storing items in local memory, a SINGLE state server, or a centralized database. Where Velocity steps in is when you need more than a single state server (cache in memory) and don't want to use a slow database for holding your cache.

企业应用程序块:我远离所有企业应用程序块.它们是沉重的框架,提供的比我通常需要的要多!只要你记得把所有涉及到不是你自己的代码的东西都包装起来,并遵循简单的编码规则,坚持使用任何其他方法而不是这个方法!(当然只是我的意见 - MySpace 尽可能多地利用企业应用程序块!)

Enterprise Application Block: I stay away from all of the Enterprise Application Blocks. They are heavy frameworks that give more than I generally require! As long as you remember to wrap everything that touches code that is not your own and follow simple rules for coding, stick to any of the other methods over this one! (just my opinion of course - MySpace leverages as much as they can out of Enterprise Application Blocks!)

您不必预先选择!我通常会创建一个缓存包装器,我会在我的代码中与它进行通信以获取诸如 Get、Set、Exists、Remove、ListKeys 等方法的信息.这然后指向可以指向 MemCached、Velocity 或 .NET 缓存的底层缓存抽象级别.我使用 StructureMap(或选择另一个 IoC 容器)来注入我想用于给定环境的缓存形式.在我的本地开发箱中,我可能会在会话中使用 .NET 缓存.在生产中,我通常使用 MemCached Win 32.但无论它如何设置,您都可以轻松地交换内容以尝试每个系统,看看哪种最适合您.您只需要确保您的应用程序尽可能少地了解缓存的内容!一旦这个抽象层就位,您就可以执行一些操作,例如为所有进出缓存的数据运行压缩算法 (gzip),这将允许您在缓存中存储 10 倍的数据量.- 透明.

You don't have to choose up front! I generally create a cache wrapper that I communicate with in my code for methods such as Get, Set, Exists, Remove, ListKeys, etc. This then points to an underlying level of cache abstraction that can point to MemCached, Velocity, or .NET cache. I use StructureMap (or choose another IoC container) to inject which form of cache I want to use for a given environment. In my local dev box I might use .NET cache in the session. In production I generally use MemCached Win 32. But regardless of how it is set up you can easily swap things around to try each system out to see what works best for you. You just need to make sure that you application knows as little as possible about how things are cached! Once this layer of abstraction is in place you can then do things such as run a compression algorithm (gzip) for all the data that is going in and out of cache which would allow you to store 10 times the amount of data in cache. - transparently.

如果您有兴趣,我会在我的书中介绍 .NET Cache、MemCached Win32、StructureMap 和适当的抽象!

I cover .NET Cache, MemCached Win32, StructureMap, and the appropriate abstractions in my book if you are interested!

ASP.NET 3.5 社交网络(http://www.amazon.com/ASP-NET-3-5-Social-Networking-Enterprise-ready/dp/1847194788/ref=sr_1_1?ie=UTF8&s=books&qid=1225408005&sr=8-1 )Andrew Siemer www.andrewsiemer.com blog.andrewsiemer.com www.socialnetworkingin.net

ASP.NET 3.5 Social Networking (http://www.amazon.com/ASP-NET-3-5-Social-Networking-Enterprise-ready/dp/1847194788/ref=sr_1_1?ie=UTF8&s=books&qid=1225408005&sr=8-1 ) Andrew Siemer www.andrewsiemer.com blog.andrewsiemer.com www.socialnetworkingin.net

更新更改了使用 memcached 列出站点的链接.谢谢大卫注意到它坏了!

Update Changed the link that lists sites using memcached. Thank you David for noticing that it was broken!

这篇关于System.Web.Caching 与企业库缓存块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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