Topic: action caching not working in production

We're using memcache and cache_fu and for the most part we're using conditional action caching so non-authenticated user will get action cached page and autenticated user will get dynamic page with some fragment caching. Everything seems to work great on my local machine and on our staging server. In production, action caching doesn't appear to be working (though fragment caching is). Production is running six app servers with three mongrels each and production and stage use different memcache servers.

That's pretty generic, but any general things I should be checking? Just wonder if I'm missing something simple and obvious with configuration. The sysadmin isn't a big rails guy and we're all fairly new to rails 2.0 and implementing it with memcache....


Re: action caching not working in production

First step is to make sure something on the production server is not stopping the call to generate the action_cache.

A simple logger.warn("action_cache") will log it to the production log...

If thats working... then continue step by step along the route till you find the issue.

Re: action caching not working in production

Thanks for the reply. I've done something like that and have found that it looks like it's intermittent.

In the :cacheable? method that is used for the condition, I've added a logger.warn to check that the method is called and the value of the result (true or false).

Application.rb controller
  def cacheable?
    test_logged_in = logged_in? ? false : true
    logger.warn("CACHEABLE: " + test_logged_in.to_s)
    logged_in? ? false : true

HomeController (flash_message catches flash message on logout)
caches_action :index => { :ttl => 30.minutes, :if => :cacheable? } , :cache_path => {|c| c.flash_message }

def index
    respond_to do |format|
      format.html do
        unless logged_in?
          @favorite = FeatureItem.recent_favorites(1, 'entertainment')[0]
          @favorites = FeatureItem.recent_favorites(10, 'entertainment')
          render :action => 'welcome' and return false

What I'm seeing is that on occasion, it looks like the :cacheable? method is not being called for the action.

Digging deeper into the cache_fu plugin itself, I see in fragment_cache.rb that this line in before() is returning, as @actions is empty in these instances:

return unless @actions.include?(controller.action_name.intern)

Looking further up in fragment_cache.rb, I see that @actions is set in initialize:

        def initialize(*actions, &block)
          if [].respond_to?(:extract_options!)
            @options = actions.extract_options!

            @actions = actions.inject(@options.except(:cache_path)) do |hsh, action|
              action.is_a?(Hash) ? hsh.merge(action) : hsh.merge(action => { :ttl => nil })
            @actions = actions.inject({}) do |hsh, action|
              action.is_a?(Hash) ? hsh.merge(action) : hsh.merge(action => { :ttl => nil })

So from what I can tell, the index action in the home controller is being called, but *actions param is empty in fragment_cache.rb, or at least it doesn't contain what I expect. What I see when it does work is key: index, value: ifcacheable?ttl1800, and when it doesn't, @actions is empty (causing return to happen in 'return unless @actions.include?(controller.action_name.intern)')

Another note (if it matters)...index action will render welcome action if user is not logged in (:cacheable? is true), but with caching, that would only happen when cache is empty for this action, theoretically once every half hour.


Last edited by spariam (2008-05-11 00:43:45)