3

我尝试将Actionpack 页面缓存与我的静态页面一起使用。如果我理解“Actionpack 页面缓存”工作是第一个到达轨道的请求。渲染视图,并将 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

朱比

彪马服务器

生产方式

启动服务器 - RAILS_ENV=production rails s puma

我的生产.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

在控制器中我使用

caches_page :load_app
def load_app

end

这是一个根网址。

我的宝石文件

    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

请帮助我理解我做错了什么。

4

1 回答 1

4

使用页面缓存时,您应该指示您的网络服务器为写入公共目录的缓存页面提供服务。这个想法是,如果您的请求的正常路径是 /foo/bar.html,那么缓存的副本应该存储在 Rails.root/public/foo/bar.html 中。这样,请求就永远不会到达您的 Rails 应用程序。

当您将存储路径更改为 public/deploy 时,您应该注意将您的网络服务器指向该目录以从那里提供文件。我不认为 Puma 可以处理这个问题,所以你应该在前端服务器(如 Apache 或 Nginx)中处理它。

话虽如此,从 Rails 4 中删除页面缓存是有充分理由的,也许您应该研究一下俄罗斯娃娃缓存,因为它更灵活且易于使用。

于 2013-08-16T09:18:25.737 回答