Page caching feeds and cache file extensions

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

On 2/4/06, csn [email protected] 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


Rick O.
http://techno-weenie.net

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.

— Rick O. [email protected] 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

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


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


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

— csn [email protected] 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