mem*_*per 2 memcached caching ruby-on-rails-3 dalli
我最近使用Dalli gem为我的Rails应用程序实现了memcached heroku附加组件的缓存.我发现虽然部署到Heroku时,它还会缓存我的所有静态资产,包括图像,这会迅速炸毁我的memcached大小.heroku日志的样本看起来像
cache: [GET /assets/application.css] fresh
app[web.1]: cache: [GET /assets/sign-in-twitter.gif] fresh
app[web.1]: cache: [GET /assets/ajax-loader.gif] fresh
app[web.1]: cache: [GET /assets/sign-in-facebook.gif] fresh
Run Code Online (Sandbox Code Playgroud)
特别是对于索引页面,每个不同请求的缓存大小增加约5MB.这种行为是可配置的吗?我是否可以将memcached配置为仅缓存我的片段缓存而不是主动缓存每个页面中的每个图像?
使用dalli gem,In config/environments/production.rb:
config.action_dispatch.rack_cache = {
:metastore => Dalli::Client.new,
:entitystore => 'file:tmp/cache/rack/body',
:allow_reload => false
}
上面的配置将memcached中的Metastore信息缓存到文件系统的实际资产主体中.
在config/application.rb:
if !Rails.env.development? && !Rails.env.test? config.middleware.insert_before Rack::Cache, Rack::Static, urls: [config.assets.prefix], root: 'public' end
机架::静态用法:
将机架::静态中间件提供了网址具有匹配前缀的根目录.在这里,我将config.assets.prefix作为我的url前缀,默认为'/ assets'.这应该直接从public/assets目录中提供任何资产,而不是命中Rails :: Cache.这只有在生产中运行'rake assets:precompile'时才有效,否则'public/assets'中不会有预编译资产.
| 归档时间: |
|
| 查看次数: |
480 次 |
| 最近记录: |