# Caching one page breaks another

**URL:** <https://www.ruby-forum.com/t/caching-one-page-breaks-another/93073>\
**Category:** Rails\
**Created:** [April 27, 2007, 4:52am UTC](https://www.ruby-forum.com/t/caching-one-page-breaks-another/93073 "2007-04-27T04:52:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 27, 2007, 4:52am UTC](https://www.ruby-forum.com/t/caching-one-page-breaks-another/93073/1 "2007-04-27T04:52:31Z")

</div>

Hi,

I am caching the index page for a resource using caches\_page :index. Now  
it looks like when I POST a resource to the same (index-)URL which  
should be routed to the ‘create’ method, the rails app doesn’t even  
process the request (I get no log output) but the cached page is served  
instead. Is this a bug, or does one need to specify the HTTP method in  
the call to caches\_page somehow (can’t find anything in the  
documentation) to make sure that only GET requests are cached?

Ingo

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 27, 2007, 4:58am UTC](https://www.ruby-forum.com/t/caching-one-page-breaks-another/93073/2 "2007-04-27T04:58:01Z")

</div>

> I am caching the index page for a resource using caches\_page :index. Now  
> it looks like when I POST a resource to the same (index-)URL which  
> should be routed to the ‘create’ method, the rails app doesn’t even  
> process the request (I get no log output) but the cached page is served  
> instead. Is this a bug, or does one need to specify the HTTP method in  
> the call to caches\_page somehow (can’t find anything in the  
> documentation) to make sure that only GET requests are cached?

This is normal. If you cache a page/URL and make any sort of request to  
that same URL your webserver is going to “process” that page, not skip  
it  
and hand it to Rails.

Why not change your POST’s action to point to the ‘create’ route/URL  
directly?

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 27, 2007, 5:07am UTC](https://www.ruby-forum.com/t/caching-one-page-breaks-another/93073/3 "2007-04-27T05:07:00Z")

</div>

Hmm, guess I don’t understand this yet. Let’s use an example: Writing  
‘map.resources :users’ in routes.rb gives me the following routes:

GET /users/ {:action=\>“index”, :controller=\>“users”}  
POST /users/ {:action=\>“create”, :controller=\>“users”}

when I use caches\_page :index, how can I prevent a POST to /users from  
bringing up the cached index page? Or are you saying that it is not  
possible to use unmodified REST routes with caching this way?

Ingo

Philip H. wrote:

> > I am caching the index page for a resource using caches\_page :index. Now  
> > it looks like when I POST a resource to the same (index-)URL which  
> > should be routed to the ‘create’ method, the rails app doesn’t even  
> > process the request (I get no log output) but the cached page is served  
> > instead. Is this a bug, or does one need to specify the HTTP method in  
> > the call to caches\_page somehow (can’t find anything in the  
> > documentation) to make sure that only GET requests are cached?
> 
> This is normal. If you cache a page/URL and make any sort of request to  
> that same URL your webserver is going to “process” that page, not skip  
> it  
> and hand it to Rails.
> 
> Why not change your POST’s action to point to the ‘create’ route/URL  
> directly?

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 27, 2007, 4:19pm UTC](https://www.ruby-forum.com/t/caching-one-page-breaks-another/93073/4 "2007-04-27T16:19:25Z")

</div>

Thanks Philip! I will try using action caching instead, and see whether  
that makes a difference (although I would hate to lose part of the  
performance gain this way)

Ingo

Philip H. wrote:

> > Hmm, guess I don’t understand this yet. Let’s use an example: Writing  
> > ‘map.resources :users’ in routes.rb gives me the following routes:
> > 
> > GET /users/ {:action=\>“index”, :controller=\>“users”}  
> > POST /users/ {:action=\>“create”, :controller=\>“users”}
> > 
> > when I use caches\_page :index, how can I prevent a POST to /users from  
> > bringing up the cached index page? Or are you saying that it is not  
> > possible to use unmodified REST routes with caching this way?
> 
> I don’t think REST is even involved here. Your first route results in a  
> cached file to public/users/index.html. Any additional requests  
> (GET/POST/etc) to /users/ and your web server (apache/lighttpd) is going  
> to return the content in public/users/index.html and never pass the  
> request on to Rails.
> 
> -philip

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [April 27, 2007, 6:24am UTC](https://www.ruby-forum.com/t/caching-one-page-breaks-another/93073/5 "2007-04-27T06:24:06Z")

</div>

> Hmm, guess I don’t understand this yet. Let’s use an example: Writing  
> ‘map.resources :users’ in routes.rb gives me the following routes:
> 
> GET /users/ {:action=\>“index”, :controller=\>“users”}  
> POST /users/ {:action=\>“create”, :controller=\>“users”}
> 
> when I use caches\_page :index, how can I prevent a POST to /users from  
> bringing up the cached index page? Or are you saying that it is not  
> possible to use unmodified REST routes with caching this way?

I don’t think REST is even involved here. Your first route results in a  
cached file to public/users/index.html. Any additional requests  
(GET/POST/etc) to /users/ and your web server (apache/lighttpd) is going  
to return the content in public/users/index.html and never pass the  
request on to Rails.

-philip
