# Conditional action caching/memcache - not working with all actions (routes?)

**URL:** <https://www.ruby-forum.com/t/conditional-action-caching-memcache-not-working-with-all-actions-routes/137541>\
**Category:** Rails\
**Created:** [May 14, 2008, 3:09am UTC](https://www.ruby-forum.com/t/conditional-action-caching-memcache-not-working-with-all-actions-routes/137541 "2008-05-14T03:09:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gawk007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/97f17d/32.png) [@gawk007](https://www.ruby-forum.com/u/gawk007)\
**Post date:** [May 14, 2008, 3:09am UTC](https://www.ruby-forum.com/t/conditional-action-caching-memcache-not-working-with-all-actions-routes/137541/1 "2008-05-14T03:09:06Z")

</div>

I’ve been trying to track this down for a while now and have yet find  
the solution…this problem appears only to occur in production  
environment with multiple mongrels.

We’ve got several controllers using conditional action caching using  
cache\_fu plugin. Some actions work great, as I expect, others seem to  
work intermittently at mongrel startup, but quit working after a  
while.

So for example, the index action in a help controller works fine (this  
is picked up by a default route):

class HelpController \< ApplicationController  
caches\_action :index =\> {:ttl =\> 1.hour, :if =\> :cacheable?}

def index  
end  
end

However, some actions, including the main site index action seems to  
fail miserably.

Uses this route:

# Default welcome Route

map.home ‘’, :controller =\> “home”

# Note - c.flash\_message below is to pick up redirects to index page

with flash messages like one one logout, which will have a flash  
message (“You are now logged out,” etc.)

class HomeController \< ApplicationController  
before\_filter :login\_required, :except =\>  
[:index, :welcome, :public\_profile, :test]  
before\_filter :find\_account\_or\_redirect, :except =\>  
[:index, :welcome, :public\_profile, :test]  
caches\_action :index =\> { :ttl =\> 30.minutes, :if  
=\> :cacheable? } , :cache\_path =\> Proc.new {|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  
end  
.  
.  
.  
end  
end  
end  
.  
.  
.  
end

cacheable? method is in application controller (logged\_in? is in  
restful\_authentication library)

def cacheable?  
logged\_in? ? false : true  
end

About four of the actions are working perfectly, the other four or so  
fail. Any insight would be highly appreciated…
