config.assets.cache_store and Rails 4

config.assets.cache_store and Rails 4

Alex Mccaw's post on faster deploys on Heroku got us pretty psyched up. We punched our memcached credentials in:

# We use Heroku and Memcachier
# This doesn't work
config.assets.cache_store = :dalli_store, ENV["MEMCACHIER_SERVERS"], { username: ENV["MEMCACHIER_USERNAME"], password: ENV["MEMCACHIER_PASSWORD"]}  

But that didn't work.

After poking around, it seems that the DSL for config.assets.cache_store is broken in Rails 4.

You have to do this:

# This works
config.assets.configure {|env|  
  env.cache = ActiveSupport::Cache.lookup_store(:dalli_store)

If you're using memcachier like us without the gem, pass in the server credentials after # lookup_store(:dalli_store, options...)


On our largest app, we've seen a very big increase in asset compilation time across deployments from 211 seconds.

Running: rake assets:precompile
Asset precompilation completed (31.36s) # Was 211 seconds

This could be used in staging easily too since Memcachier's 25m developer version is free and pretty much enough. Just take note that the first compile will be longer because of network cost of reaching and writing memcached entries.