使用 Ruby on Rails 3 进行多级缓存

发布于 2024-11-05 08:58:39 字数 422 浏览 1 评论 0 原文

我在很多地方搜索过这个问题,但没有找到答案。 根据 Rails 指南和有关缓存的类似材料,Rails 可以使用其中一种缓存类型:内存中、文件存储、memcached、自定义缓存类等。

但是,如果我想在一个应用程序中根据缓存的实体使用两种或三种缓存类型,该怎么办?

例如(高负载新闻聚合器):我有几个前端 Rails 服务器、几个带有分片 MongoDB 的服务器和一个用于 memcached 的服务器。 创建

  1. 如果我想在前端为新闻部分和支持数据的经常使用的小型集合(以避免从 memcached 获取数据的网络延迟)
  2. memcached 用于最常阅读的最新新闻

  3. 文件存储缓存(可以存储在所有前端挂载的一个网络文件存储中)用于存档新闻(必须缓存以避免频繁的标记处理,但太大而无法存储在内存中)

I've searched about this question in many places, but haven't found answer.
According to rails guides and similar materials about caching, rails can use one of such cache types: in-memory, file storage, memcached, custom cache classes, and so on.

But what if I want to use two or three cache types in one application, depending on cached entity?

For example (a high-load news agregator): I have a couple of front-end rails servers, couple of servers with sharded MongoDB and one server for memcached. What if I want to make

  1. per-node in-memory cache on front-ends for very often used tiny collections (to avoid network latency acquiring data from memcached) for news sections and support data

  2. memcached for most read latest news

  3. file storage cache (can be stored in one network file storage mounted for all front-ends) for archive news (must be cached to avoid frequent mark-up processing, but is too big to store it in memory)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤蝉 2024-11-12 08:58:39

据我所知没有缓存插件或机制可以实现您想要的精细定制。您始终可以编写自己的缓存存储,根据缓存的内容委托给另一个子系统。

AFAIK there's no cache plugin or mechanism that enables the fine customization you desire. You can always write your own cache store that delegates to another subsystems according to what's being cached.

七度光 2024-11-12 08:58:39

我一直在寻找同样的东西。 “level2”可能就是您正在寻找的。仓库:https://github.com/mezis/level2 Rubygems 条目:https://rubygems.org/gems/level2/versions/0.2.5 一个巨大的问题是它不适用于 dalli,这是与 memcached 交互的正常方式:https://github。 com/mezis/level2/issues/6

我还发现了layercake,但似乎已被放弃:https:// github.com/phaza/layercake

我真的希望 Rails 有这样的东西,这似乎是一个共同的愿望。

我正在考虑自己写这样的东西,或者至少为本地内存缓存和内存创建一个单独的助手。然后使用“正常”Rails 缓存系统进行“正常”缓存调用,作为解决此问题的一部分: https://github.com/coreinfrastruct/best-practices-badge/issues/1481

I was looking for the same thing. 'level2' may be what you're looking for. Repo: https://github.com/mezis/level2 Rubygems entry: https://rubygems.org/gems/level2/versions/0.2.5 A huge problem is that it doesn't work with dalli, the normal way to interact with memcached: https://github.com/mezis/level2/issues/6

I also found layercake but that appears abandoned: https://github.com/phaza/layercake

I really wish Rails had such a thing, it seems like a common desire.

I'm thinking about writing something like this myself, or at least creating a separate helper for a local memory cache & then using the "normal" Rails cache system for "normal" cache calls, as part of resolving this issue: https://github.com/coreinfrastructure/best-practices-badge/issues/1481

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文