1

Using Rails 3.1.1 on Heroku, Dalli gem and Memcachier.

I am trying to troubleshoot an issue where keys disappear from Memcachier, in order to do this I would like to make sure that only the content from my caches_action will be cached in the memcache. I would like my assets (jpg's etc) to be cached elsewhere.

I believe it is the same issue as this question but when I do the same, i.e. adding

config.action_dispatch.rack_cache = {
  :metastore    => Dalli::Client.new,
  :entitystore  => 'file:tmp/cache/rack/body',
  :allow_reload => false
}

to my production.rb, it doesn't really seem to do anything.

My production.rb in full:

MyDemoApp::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 = true

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

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

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

  # 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

  # 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

  # Prepend all log lines with the following tags
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

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

  config.action_dispatch.rack_cache = {
    :metastore    => Dalli::Client.new,
    :entitystore  => 'file:tmp/cache/rack/body',
    :allow_reload => false
  }  

  # Set expire header of 30 days for static files
  config.static_cache_control = "public, max-age=2592000" 

  # 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( search.js )

  # Disable delivery errors, bad email addresses will be ignored
  # config.action_mailer.raise_delivery_errors = false

  # 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
end

Caching assets work fine (get cache fresh-responses) and caching actions like this:

  caches_action :show, :layout => false, :expires_in => 3.days

Also creates a cached entry in Rails cache (although they disappear after a while).

My question now is: How can I, if possible, do so that only my caches_action fragments end up in my Memcache (and not my assets)?

A bonus question would be, do you see anything out of the ordinary in my production.rb?

Community
  • 1
  • 1
Christoffer
  • 2,271
  • 3
  • 26
  • 57

1 Answers1

0

I use the gem 'asset_sync' to move all my assets out to Amamzon S3

See Instructions here

You get three advantages:

  • Your assets are served from Amazon so the page loads faster for the user
  • Your slug size on Heroku is smaller and is supposed to be more performant
  • Your assets will no longer be in memecahce

All my assets cost me about 20cents every three month to host on Amamzon

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Mark Stratmann
  • 1,612
  • 14
  • 21
  • Please do not use signatures/taglines in your posts. Your user box counts as your signature, and you can use your profile to post any information about yourself you like. [FAQ on signatures/taglines](http://stackoverflow.com/faq#signatures) – Andrew Barber Jan 22 '13 at 23:17