# Page caching feeds and cache file extensions

**URL:** <https://www.ruby-forum.com/t/page-caching-feeds-and-cache-file-extensions/53425>\
**Category:** Rails\
**Created:** [February 4, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/page-caching-feeds-and-cache-file-extensions/53425 "2006-02-04T22:17:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![csn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@csn](https://www.ruby-forum.com/u/csn)\
**Post date:** [February 4, 2006, 10:17pm UTC](https://www.ruby-forum.com/t/page-caching-feeds-and-cache-file-extensions/53425/1 "2006-02-04T22:17:22Z")

</div>

I have a feeds controller which generates RSS and Atom pages. I put  
‘caches\_page :show’ in it. The problem is that the pages are saved with  
an html extension. As a result, browsers display the cached feeds as  
HTML rather than XML, and feed validators complain.

There’s an option to set ‘Base.page\_cache\_extension’ globally, but I  
don’t want to do that for everything. I also tried setting that option  
just in the show method, but that doesn’t work. How can I get the cached  
pages for just Feeds#show get saved with xml/rss/atom extensions?

Thanks  
csn

---

<div class="post-metadata">

**Author:** ![csn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@csn](https://www.ruby-forum.com/u/csn)\
**Post date:** [February 4, 2006, 10:28pm UTC](https://www.ruby-forum.com/t/page-caching-feeds-and-cache-file-extensions/53425/2 "2006-02-04T22:28:42Z")

</div>

On 2/4/06, csn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks  
> csn

It’s kind of hackish I think, but I set it in the route, and then send  
it to the correct action in the controller:

map.xml ‘xml/:file’, :controller =\> ‘syndicate’, :action =\> ‘xml’,  
:requirements =\> { :file =\> /^\w+.xml$/ }

[http://collaboa.techno-weenie.net/repository/file/rails\_help/app/controllers/syndicate\_controller.rb](http://collaboa.techno-weenie.net/repository/file/rails_help/app/controllers/syndicate_controller.rb)

–  
Rick O.  
[http://techno-weenie.net](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![csn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@csn](https://www.ruby-forum.com/u/csn)\
**Post date:** [February 5, 2006, 4:12am UTC](https://www.ruby-forum.com/t/page-caching-feeds-and-cache-file-extensions/53425/3 "2006-02-05T04:12:47Z")

</div>

csn wrote:

> Thanks  
> csn

I ended up setting the content-type conditionally in lighttpd based on  
the path. I’m sure you can do the same in Apache.

---

<div class="post-metadata">

**Author:** ![csn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@csn](https://www.ruby-forum.com/u/csn)\
**Post date:** [February 5, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/page-caching-feeds-and-cache-file-extensions/53425/4 "2006-02-05T20:31:11Z")

</div>

— Rick O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > csn
> 
> It’s kind of hackish I think, but I set it in the  
> route, and then send  
> it to the correct action in the controller:
> 
> map.xml ‘xml/:file’, :controller =\> ‘syndicate’,  
> :action =\> ‘xml’,  
> :requirements =\> { :file =\> /^\w+.xml$/ }

[http://collaboa.techno-weenie.net/repository/file/rails\_help/app/controllers/syndicate\_controller.rb](http://collaboa.techno-weenie.net/repository/file/rails_help/app/controllers/syndicate_controller.rb)

Rick

Thanks. What does your caches\_page\_with\_references  
function do? I briefly looked around your repository,  
but didn’t see its definition.

csn

> –  
> Rick O.  
> [http://techno-weenie.net](http://techno-weenie.net)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[\[object](https://mail.yahoo.com/)**
>
> \[object

---

<div class="post-metadata">

**Author:** ![csn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@csn](https://www.ruby-forum.com/u/csn)\
**Post date:** [February 5, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/page-caching-feeds-and-cache-file-extensions/53425/5 "2006-02-05T20:43:15Z")

</div>

— csn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> don’t want to do that for everything. I also tried  
> setting that option  
> just in the show method, but that doesn’t work. How  
> can I get the cached  
> pages for just Feeds#show get saved with  
> xml/rss/atom extensions?

I’ve made some progress. Changing  
@@page\_cache\_extension to ‘.xml’ in the controller  
causes the cache files to get saved with an xml  
entension. However, I can’t get them to get used. I  
added this to my .htaccess:

RewriteRule ^(feeds/[^.]+)$ $1.xml [QSA]  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ dispatch.cgi [QSA,L]

above the standard:

RewriteRule ^([^.]+)$ $1.html [QSA]  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ dispatch.cgi [QSA,L]

The production shows that xml cache files aren’t used,  
but html ones are. I even tried just this in the  
.htaccess:

RewriteRule ^([^.]+)$ $1.xml [QSA]  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ dispatch.cgi [QSA,L]

But those cache files STILL aren’t getting used. The  
above ruleset should cause EVERY request sans file  
extension to get rewritten to $1.xml, but it  
apparently isn’t working. I have no idea why. Only  
.html works. I’m using webrick (in production mode).  
Any ideas?

Thanks,  
csn

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[\[object](https://mail.yahoo.com/)**
>
> \[object
