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

查看:86
本文介绍了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.

  • 您使用什么?
  • 为什么?

在Web应用程序外部使用安全吗?我看到的信息不一,但我认为答案可能并非完全如此.

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

我不希望使用其亮点之一, 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

速度:这是Microsoft对诸如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 Win32.但是,无论如何设置,您都可以轻松地交换内容来尝试每个系统,以查看最适合您的系统.您只需要确保您的应用程序对事物的缓存方式了解得越少越好!一旦有了这一抽象层,您就可以执行诸如对所有进出缓存的数据运行压缩算法(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列出站点的链接.谢谢David注意到它已损坏!

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

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

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