I am trying to use action caching to cache an action and then manually expire it using another action called refresh. I know the Rails best practice is to use a sweeper but that doesn’t work either. This works great locally with WebBrick but when I deploy to Apache using Phusion Passenger, I cannot get the cache to expire. It appears that expire_action is expiring the wrong action by omitting index from the cache path.
bills_controller.rb
class BillsController < ApplicationController
caches_action :index
def index
...
end
def refresh
expire_action :action => :index
redirect_to :action => :index
end
When I navigate to http://www.mysite.org/bills, /log/production.log shows this:
Started GET "/bills"
Rendered bills/index.html.erb
Write fragment views/www.mysite.org/bills/index
Then when I navigate to http://www.mysite.org/refresh, /log/production.log shows this:
Started GET "/bills/refresh"
Expire fragment views/www.mysite.org/bills <<<<Culprit?
Redirected to http://www.mysite.org/bills
Started GET "/bills"
Read fragment views/www.mysite.org/bills/index
Notice that Expire fragment views/www.mysite.org/bills does not include the /index portion. I suspect this is the reason the cache is not expiring but I am not sure.
My apache config for the site looks like this:
<VirtualHost *:80>
ServerName www.mysite.org
DocumentRoot /var/www/html/mysite.org/public
<Directory /var/www/html/mysite.org/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
I think this problem was caused because I was using inheritance for my controllers and had some caches_action directives in my base class. The caches_action overrides in the child controllers were not overriding as I expected (and inconsistently with WebBrick). I simply removed the caches_action directives in my base classes and this fixed my problem.