下午好,
我在 Heroku 上的应用程序中连接了 Memcached。免费托管计划的限制为 Memcached 为 5MB,Memcachier 为 25MB。作为几乎所有事物的新手,我只是希望澄清这到底代表什么。
我在配置文件中设置了 DalliStore,并为 Rack::Cache 设置了典型选项。我的元存储在 Memcache 中,实体存储设置在文件系统上。
问题:
config.cache_store = :dalli_store
和
config.action_dispatch.rack_cache = {
:verbose => true,
:metastore => Dalli::Client.new,
:entitystore => 'file:tmp/cache/rack/body',
:allow_reload => false
}
最佳答案
我一直在努力解决类似的问题。
首先,让我们弄清楚我们的术语。
Rails.cache
) 具有单个 API,可以配置为使用不同的 Ruby 软件实现。 config.cache_store
的一种设置是 :memory_store
使用内存中的实现。另一个设置是 :dalli_store
指定使用 dalli gem,它在引擎盖下与您的 memcached 服务器建立可能的远程连接。 为了让 Rack::Cache 在请求到达 Rails 堆栈和应用程序的其余部分之前处理请求,它必须在某处存储响应 + 元数据。它存储东西的地方由
config.action_dispatch.rack_cache = { ... }
配置。环境。请注意,这是与
config.cache_store = :dalli_store
不同的设置.他们不必有关系。我认为这是很多困惑的来源。但在实践中,我们可能希望它们都使用 memcached,这意味着使用 dalli 实现。然而,他们每个人都有自己的Dalli::Client
实例。 (此外,您的 session_store 可能是相关的,但不一定是。)Heroku cedar 堆栈有一个 ephemeral file system这不能在 dynos 之间共享。然而,Heroku 自己 recommend using tmp file storage with Rack::Cache为
entitystore
仅,memcached 用于 metastore
.至于实际存储在 Rack::Cache 元存储中的内容,这些是来自 rack-cache v1.2
Rack::Cache::MetaStore
的文档。类(class):The MetaStore is responsible for storing meta information about a
request/response pair keyed by the request's URL.
The meta store keeps a list of request/response pairs for each canonical
request URL. A request/response pair is a two element Array of the form:
[request, response]
The +request+ element is a Hash of Rack environment keys. Only protocol
keys (i.e., those that start with "HTTP_") are stored. The +response+
element is a Hash of cached HTTP response headers for the paired request.
因此,为了回答您的问题,HTTP 请求 header 和 HTTP 响应 header 存储在 Rack::Cache 元存储中。另一方面,Rack::Cache 实体存储存储整个响应主体(即 HTML)。
自 you can't use page caching reliably on Heroku ,这意味着您可能正在使用 Action 缓存和片段缓存。 Action 和片段缓存使用您的 Rails 缓存存储(而不是机架缓存)。但是,如果您将它们设置为在物理上使用相同的 memcached 服务器,则它们都将有助于内存使用。操作和部分缓存存储实际的 HTML。
为了更深入地了解您的实际使用情况,如果您使用的是 memcachier,请运行以下命令在浏览器中打开分析仪表板。
heroku addons:open memcachier
见 this question有关获取 memcached 统计信息的更多信息。
关于ruby-on-rails - Memcached 大小限制对于文件系统实体存储究竟代表什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10115187/