Как заставить работать кэширование активов - PullRequest
2 голосов
/ 15 марта 2012

Я пытаюсь перейти на кедр / конвейер активов и что-то теряюсь.

Все отображается нормально, но мое приложение выглядит заметно медленнее. Просматривая свои бревна, я вижу тонны подобных вещей:

2012-03-15T17: 03: 02 + 00: 00 приложение [web.1]: кэш: [GET /assets/application.js] miss 2012-03-15T17: 03: 02 + 00: 00 app [web.1]: кеш: [GET /assets/down_arrow.gif] пропущен 2012-03-15T17: 03: 02 + 00: 00 приложение [web.1]: кеш: [GET /assets/application.css] miss

Я ожидаю, что это будут хиты - верно?

Моя продукция.рб

  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # For nginx:
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

  # I also tried these
  # config.action_dispatch.x_sendfile_header = "X-Sendfile"
  # config.action_dispatch.x_sendfile_header = nil

  config.cache_store = :dalli_store

Мое приложение.rb

...

    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'

    config.assets.initialize_on_precompile = false

    config.active_support.deprecation = :log

Примечание: assets:precompile отлично работает при развертывании:

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
-----> Rails plugin injection
       Injecting rails_log_stdout
       Injecting rails3_serve_static_assets

Спасибо! Дайте мне знать, если вам нужна дополнительная информация

Ответы [ 2 ]

0 голосов
/ 21 марта 2012

Я поднял билет поддержки с герою и тут был ответ:

Я бы попробовал: http://jackchu.com/blog/2011/09/20/rails-asset-pipeline-content-delivery-networks-and-rack-cache/

Недавние исследования Rack :: Cache и memcached / dalli, кажется, сломано в Rails 3.1 +.

Кажется, это сработало. Я с нетерпением жду исправления взаимодействия между Rack :: Cache и dalli, но в то же время я буду следовать подходу @jackchu

0 голосов
/ 17 марта 2012

вы, вероятно, пропустили одну из многих конфигураций конвейера активов. взгляните на мой файл production.rb:

HamburgOnRuby::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb

  # Code is not reloaded between requests
  config.cache_classes = true

  # Full error reports are disabled and caching is turned on
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Don't fallback to assets pipeline if a precompiled asset is missed
  # config.assets.compile = false

  # Generate digests for assets URLs
  config.assets.digest = true

  # Compress both stylesheets and JavaScripts
  config.assets.js_compressor  = :uglifier
  config.assets.css_compressor = :scss

  # Defaults to Rails.root.join("public/assets")
  # config.assets.manifest = YOUR_PATH

  # Specifies the header that your server uses for sending files
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
  config.action_dispatch.x_sendfile_header = nil # http://devcenter.heroku.com/articles/rails31_heroku_cedar#the_asset_pipeline

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # See everything in the log (default is :info)
  # config.log_level = :debug

  # Use a different logger for distributed setups
  # config.logger = SyslogLogger.new

  # Use a different cache store in production
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server
  # config.action_controller.asset_host = "http://assets.example.com"

  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
  config.assets.precompile += %w( active_admin.js active_admin.css )

  # Disable delivery errors, bad email addresses will be ignored
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.smtp_settings = {
    :address        => "smtp.sendgrid.net",
    :port           => "25",
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => ENV['SENDGRID_DOMAIN']
  }

  # Enable threaded mode
  # config.threadsafe!

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation can not be found)
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners
  config.active_support.deprecation = :notify

  # Set the default host for production
  config.default_host = 'onruby.de'
end
...