Search code examples
ruby-on-railsmemcacheddalli

Memcached (Dalli) and expiration time for caches_action


I'm using Memcached and Dalli store for my rails app.

Is there a way to set something like expires_in and gzip for caches_action?


Solution

  • Just add them to the caches_action invocation line as cache parameters; all parameters that are not specific to caches_action will be passed to the actual memcache fetch call.

    caches_action :show, :unless => proc {current_user},
      :cache_path => proc {"post_#{params[:id]}"},
      :expires_in => 10.seconds,
      :race_condition_ttl => 2.seconds
    

    I use Dalli and Rails 3.1.3, and this code works as intended. I suppose, gzipping would also work.