views:

146

answers:

2

I have a very fundamental understanding problem with Rails page caching mechanism.

On a rails 2.0.5 application, I use a lot of full page caching, everything's working fine, pages are served at great speed by apache.

So far all the content was handled in an admin section, the cache sweepers are working well.

But I have now opened the edition of some sections to the users, who don't go through the "admin" namespace, but the regular routes.

the problem is that it seems when the updates are performed, they don't go to mongrel with the "put" action, instead I just get the cached page (no action in the database, no flash message, no nothing....)

I feel like I missed something here, is it possible to use page caching with regular REST routes ? or do I have a problem with my mongrel/apache configuration ?

+1  A: 

You're probably caching too much of the page. If you're caching the entire page and then altering the contents of that page via a put action, the page won't register the change unless you clear the cache explicitly.

If you have a copy 'The Rails Way', some great examples are given to expire pages so that they are reloaded on the next load.

More or less, you have to do something like the following within your create action:

expire_page :action => 'index'

You can also create an observer to observe your model and expire the cache without needing to explicitly call it after a create or update action.

Hope that helps.

-Chris

Christopher Hazlett
A: 

thanks for your answer, but it is not what I meant, the full page cache mechanism works fine, I have dedicated sweepers in the admin controllers that refresh the pages.

my problem is (or I think it is) that when the models are updated through the regular controllers, the form is submitted to the cached page and not to the appropriate action.

in the form

/pages/1-hello/edit
form should be posted with "put" method on "/pages/1-hello"

but I believe it goes to the cached page '/pages/1-hello.html' and is treated as a regular get....

When I submit the form, I just see the show action, no flash message, nothing updated. then I erase the cached file in my public directory, submit the form again and suddenly everything works....

I read the cache section in "the rails way" and the tutorial on railsenvy.com but I never seen anything mentionned about cached pages that would bring such problems....

jujudellago
I've never heard of this problem. It looks like it's translating the call as a get request, which would cause the display and use of the cached page. Can you recreate the problem on your dev site? Do you have any logs of the call that we can take a look at?
Christopher Hazlett