我在很多地方搜索过这个问题,但没有找到答案。
根据 Rails 指南和有关缓存的类似材料,Rails 可以使用其中一种缓存类型:内存中、文件存储、memcached、自定义缓存类等。
但是,如果我想在一个应用程序中根据缓存的实体使用两种或三种缓存类型,该怎么办?
例如(高负载新闻聚合器):我有几个前端 Rails 服务器、几个带有分片 MongoDB 的服务器和一个用于 memcached 的服务器。 创建
- 如果我想在前端为新闻部分和支持数据的经常使用的小型集合(以避免从 memcached 获取数据的网络延迟)
memcached 用于最常阅读的最新新闻
文件存储缓存(可以存储在所有前端挂载的一个网络文件存储中)用于存档新闻(必须缓存以避免频繁的标记处理,但太大而无法存储在内存中)
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
-
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
-
memcached for most read latest news
-
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)
发布评论
评论(2)
据我所知没有缓存插件或机制可以实现您想要的精细定制。您始终可以编写自己的缓存存储,根据缓存的内容委托给另一个子系统。
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.
我一直在寻找同样的东西。 “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