我尝试在我的静态页面中使用 Actionpack页面缓存。 如果我理解工作'Actionpack页面缓存'是第一个请求到达rails。渲染了视图,并将Html存储在缓存public / deploy /...
中第二个类似的请求没有到达轨道。视图不会呈现。将从缓存中获取一个页面。
但是在日志中它看起来完全不同。
“第一次请求”
I, [2013-08-16T12:24:43.591000 #16835] INFO -- : Rendered init/scene.html.erb within layouts/application (4.0ms)
I, [2013-08-16T12:24:43.615000 #16835] INFO -- : Rendered layouts/_server_params.html.erb (4.0ms)
I, [2013-08-16T12:24:43.624000 #16835] INFO -- : Rendered windows/_login_without_social_window.html.erb (2.0ms)
I, [2013-08-16T12:24:43.661000 #16835] INFO -- : Rendered windows/_choice_base_career_window.html.erb (34.0ms)
I, [2013-08-16T12:24:43.687000 #16835] INFO -- : Rendered windows/_auth_window.html.erb (21.0ms)
I, [2013-08-16T12:24:43.691000 #16835] INFO -- : Rendered windows/_free_teams_window.erb (2.0ms)
I, [2013-08-16T12:24:43.692000 #16835] INFO -- : Rendered layouts/_windows.html.erb (74.0ms)
I, [2013-08-16T12:24:43.775000 #16835] INFO -- : Rendered layouts/_bottom_menu.html.erb (80.0ms)
I, [2013-08-16T12:24:43.780000 #16835] INFO -- : Write page /home/pri/test/public/deploy/init/load_app.html (1.0ms)
I, [2013-08-16T12:24:43.782000 #16835] INFO -- : Completed 200 OK in 208ms (Views: 200.0ms | ActiveRecord: 0.0ms)
I, [2013-08-16T12:24:49.070000 #16835] INFO -- : Started GET "/init/load_app" for 127.0.0.1 at 2013-08-16 12:24:49 +0400
I, [2013-08-16T12:24:49.088000 #16835] INFO -- : Processing by InitController#load_app as HTML
“第二次请求”
I, [2013-08-16T12:24:49.096000 #16835] INFO -- : Rendered init/scene.html.erb within layouts/application (1.0ms)
I, [2013-08-16T12:24:49.108000 #16835] INFO -- : Rendered layouts/_server_params.html.erb (2.0ms)
I, [2013-08-16T12:24:49.112000 #16835] INFO -- : Rendered windows/_login_without_social_window.html.erb (1.0ms)
I, [2013-08-16T12:24:49.124000 #16835] INFO -- : Rendered windows/_choice_base_career_window.html.erb (10.0ms)
I, [2013-08-16T12:24:49.138000 #16835] INFO -- : Rendered windows/_auth_window.html.erb (11.0ms)
I, [2013-08-16T12:24:49.140000 #16835] INFO -- : Rendered windows/_free_teams_window.erb (1.0ms)
I, [2013-08-16T12:24:49.142000 #16835] INFO -- : Rendered layouts/_windows.html.erb (31.0ms)
I, [2013-08-16T12:24:49.161000 #16835] INFO -- : Rendered layouts/_bottom_menu.html.erb (16.0ms)
I, [2013-08-16T12:24:49.165000 #16835] INFO -- : Write page /home/pri/test/public/deploy/init/load_app.html (3.0ms)
I, [2013-08-16T12:24:49.167000 #16835] INFO -- : Completed 200 OK in 76ms (Views: 70.0ms | ActiveRecord: 0.0ms)
在所有请求中,视图将被渲染,缓存页面将被覆盖。
我用: rails 4.0.0
jruby
美洲狮服务器生产模式
启动服务器 - RAILS_ENV =生产rails s puma
my production.rb
ResFm::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.cache_store = :dalli_store
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.assets.debug = false
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
# cache static pages
config.action_controller.page_cache_directory = "#{Rails.root.to_s}/public/deploy"
config.serve_static_assets = true
#CDN google servers
config.asset_host = 'http://resassets.appspot.com'
end
在Controller中我使用
caches_page :load_app
def load_app
end
这是一个根网址。
我的Gemfile
gem 'rails', '4.0.0'
gem 'activerecord-jdbcpostgresql-adapter', '~>1.3.0.beta2'
gem 'dalli'
gem 'jquery-ui-rails'
gem 'jquery-rails'
group :assets do
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'therubyrhino'
gem 'execjs'
end
group :development do
gem 'annotate'
gem 'puma'
end
gem 'dimensions-rails'
gem 'sass-rails', '~> 4.0.0'
group :production do
gem 'rack-cache'
gem 'actionpack-page_caching'
end
请帮助我理解我做错了什么。
答案 0 :(得分:4)
使用页面缓存时,您应该指示您的Web服务器提供在公共目录中编写的缓存页面。我们的想法是,如果您的请求的正常路径是/foo/bar.html,则缓存的副本应存储在Rails.root / public / foo / bar.html中。这样,请求永远不会到达您的Rails应用程序。
当您将存储路径更改为public / deploy时,您应该注意将Web服务器指向该目录以从那里提供文件。我认为Puma不会处理它,所以你应该在前端服务器(如Apache或Nginx)中处理它。
话虽如此,页面缓存已经从Rails 4中删除了,因为它更加灵活和易于使用,因此您应该查看Russian Doll Caching。