Caches_action :index for site root gets propagated to lower

Hello all,

I am running a blog system which has its “/” (home page) cached like
this:

class ApplicationController < ActionController::Base
before_filter :index_cache_expirer, :only => [:index]
caches_action :index

so the site’s top page is caches for 60 seconds in my case
(index_cache_expirer is a home-made function to expire)

on the site, there is also a multi-user /admin area, which in turn has
its own controllers with :index action.

The problem is that effect of “caches_action :index” directive, which
is set inside the application.rb, somehow gets propagated to, say,
:index action of admin/posts controller, which causes problems because
a user is sometimes served by a page, which was cached by another user!
(like, logging in and checking his own posts list, just to be served by
a cached posts list, which was created for another user)

I might not be doing the caching the right way or something, but is
there a way to turn off that caches_action directive propagation to
“lower” level of the site (i.e. just make it work ONLY for the
application controller’s :index action, where it was defined in?)

Any suggestions are very appreciated as my site is now running with
caching off while I’m trying to find a good solution for the problem.

TIA,
Mike

(index_cache_expirer is a home-made function to expire)

I might not be doing the caching the right way or something, but is
there a way to turn off that caches_action directive propagation to
“lower” level of the site (i.e. just make it work ONLY for the
application controller’s :index action, where it was defined in?)

Any suggestions are very appreciated as my site is now running with
caching off while I’m trying to find a good solution for the problem.

Well, every controller you have inherits from ApplicationController
(see
the “class” line at the top). So by putting this into
ApplicationController you’re telling it to apply to every controller’s
index action.

Move that caches_action line out of ApplicationController and put it
into
whatever controller serves up your home page.

-philip

Philip,
thank you very much!
Indeed! Somehow I just didn’t happen to think about this inheritancy as
the source of the problem! Now thinking about it, it is almost a
miracle I didn’t have more problems with the program, since I have put
pretty alot of various stuff inside the ApplicationController. Got to
rebuild my app’s structure a little I guess.

Thanks again!
Mike.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs