Bra*_*don 7 memcached ruby-on-rails heroku
下午好,
我把Memcached连接到Heroku上的应用程序中.免费托管计划的限制是Memcached为5MB,Memcachier为25MB.作为几乎所有事物的新手,我只是希望澄清这代表什么.
我在配置文件中设置了DalliStore,并为Rack :: Cache设置了典型选项.我的Metastore在Memcache中,并且在文件系统上设置了权限存储.
问题:
Rack :: Cache和Memcache(通过Dalli商店)之间的细分/故事究竟是什么?它们是否有不同的用途?他们做同样的事吗?即以下代码是多余的
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
}
Run Code Online (Sandbox Code Playgroud)
我一直在努力解决类似的问题.
首先,让我们的术语直截了当.
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雪松堆栈有一个短暂的文件系统,不能在dynos之间共享.然而,Heroku的自我推荐使用tmp文件存储与机架::缓存为entitystore唯一的,与用于分布式缓存metastore.
至于实际存储在Rack :: Cache Metastore中的内容,这些是来自rack-cache v1.2Rack::Cache::MetaStore类的文档:
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.
Run Code Online (Sandbox Code Playgroud)
因此,为了回答您的问题,HTTP请求标头和HTTP响应标头存储在Rack :: Cache Metastore中.另一方面,Rack :: Cache实体库存储整个响应主体(即HTML).
由于您无法在Heroku上可靠地使用页面缓存,这意味着您可能正在使用操作缓存和片段缓存.操作和片段缓存使用您的Rails缓存存储(而不是机架缓存).但是如果你将它们都设置为物理上使用相同的memcached服务器,它们都会有助于内存使用.操作和部分缓存存储实际的HTML.
为了更深入地了解您的实际使用情况,如果您正在使用memcachier,请运行以下命令在浏览器中打开分析仪表板.
heroku addons:open memcachier
Run Code Online (Sandbox Code Playgroud)
有关获取memcached统计信息的详细信息,请参阅此问题.
| 归档时间: |
|
| 查看次数: |
2150 次 |
| 最近记录: |