什么是多层缓存?
我最近遇到了与多层架构相关的短语“多层缓存”,但没有对这种缓存是什么(或者如何使用它)进行有意义的解释。
对该短语的相关在线搜索也没有真正找到任何结果。我的解释是为某些 n 层 Web 应用程序的所有层提供服务的缓存。也许是分布式缓存,每一层都有一个缓存节点。
SO 以前遇到过这个词吗?我说得对吗?还差得远吗?
I've recently come across the phrase "multi-tier cache" relating to multi-tiered architectures, but without a meaningful explanation of what such a cache would be (or how it would be used).
Relevant online searches for that phrase don't really turn up anything either. My interpretation would be a cache servicing all tiers of some n-tier web app. Perhaps a distributed cache with one cache node on each tier.
Has SO ever come across this term before? Am I right? Way off?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这已经很旧了,但我想我应该在这里投入两分钱,因为我已经编写了几个多层缓存,或者至少是多层缓存的几次迭代。
考虑一下这一点;每个应用程序都有不同的层,并且在每个层可以缓存不同形式的信息。每个缓存项通常会由于以下两个原因之一而过期:一段时间已过期,或者依赖项已更新。
对于这个解释,让我们假设我们有三层:
每一层都依赖于它的父层,我们将使用某种形式的依赖关系分配来定义这些层。所以块依赖于对象,而对象又依赖于模板。如果一个Object发生了变化,Block中的任何依赖关系都将被删除并刷新;如果模板发生更改,任何对象依赖关系都将被删除,进而删除任何块,并且所有块都将被刷新。
有几个好处,较长的过期时间是一个很大的好处,因为依赖关系将确保每当父级更新时下游资源都会更新,因此您不会获得过时的缓存资源。块缓存本身就有很大帮助,因为缺少整个页面缓存(需要 AJAX 或 Edge Side Includes 以避免缓存动态内容),块将是最接近最终用户浏览器/界面的元素,并且可以节省大量的预处理工作循环。
不过,像这样的多层缓存的复杂之处在于,它通常不能依赖于纯粹基于数据库的外键删除,也就是说,除非每个层与其父层的关系是 1:1(即,块将仅依赖于单个对象,依赖于单个模板)。您必须以编程方式解决依赖资源的删除问题。您可以通过数据库中的存储过程来执行此操作,如果您想动态使用删除规则,也可以在应用程序层中执行此操作。
希望对某人有所帮助:)
编辑:我应该补充一点,这些层中的任何一层都可以在缩放环境中进行集群、分片或其他方式,因此该模型在小型和大型环境中都适用。
I know this is old, but thought I'd toss in my two cents here since I've written several multi-tier caches, or at least several iterations of one.
Consider this; Every application will have different layers, and at each layer a different form of information can be cached. Each cache item will generally expire for one of two reasons, either a period of time has expired, or a dependency has been updated.
For this explanation, lets imagine that we have three layers:
Each layer depends on it's parent, and we would define those using some form of dependency assignment. So Blocks depend on Objects which depend on Templates. If an Object is changed, any dependencies in Block would be expunged and refreshed; if a Template is changed, any Object dependencies would be expunged, in turn expunging any Blocks, and all would be refreshed.
There are several benefits, long expiry times are a big one because dependencies will ensure that downstream resources are updated whenever parents are updated, so you won't get stale cached resources. Block caches alone are a big help because, short of whole page caching (which requires AJAX or Edge Side Includes to avoid caching dynamic content), blocks will be the closest elements to an end users browser / interface and can save boatloads of pre-processing cycles.
The complication in a multi-tier cache like this though is that it generally can't rely on a purely DB based foreign key expunging, that is unless each tier is 1:1 in relation to its parent (ie. Block will only rely on a single object, which relies on a single template). You'll have to programmatically address the expunging of dependent resources. You can either do this via stored procedures in the DB, or in your application layer if you want to dynamically work with expunging rules.
Hope that helps someone :)
Edit: I should add, any one of these tiers can be clustered, sharded, or otherwise in a scaled environment, so this model works in both small and large environments.
在使用 EhCache 几周后,仍然不完全清楚术语“多层”缓存的含义。我将跟进我解释的隐含含义;如果在任何时候有人出现并知道其他情况,请随时回答,我将删除此内容。
多层缓存似乎是一种复制和/或分布式缓存,位于n 层架构中的1+层上。它允许多个层上的组件访问相同的缓存。在 EhCache 中,使用复制或分布式缓存架构并结合简单地引用来自多个层的相同缓存服务器来实现这一点。
After playing around with EhCache for a few weeks it is still not perfectly clear what they mean by the term "multi-tier" cache. I will follow up with what I interpret to be the implied meaning; if at any time down the road someone comes along and knows otherwise, please feel free to answer and I'll remove this one.
A multi-tier cache appears to be a replicated and/or distributed cache that lives on 1+ tiers in an n-tier architecture. It allows components on multiple tiers to gain access to the same cache(s). In EhCache, using a replicated or distributed cache architecture in conjunction with simply referring to the same cache servers from multiple tiers achieves this.