# Caching only certain formats (xml) of an action

**URL:** <https://www.ruby-forum.com/t/caching-only-certain-formats-xml-of-an-action/127403>\
**Category:** Rails\
**Created:** [January 28, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/caching-only-certain-formats-xml-of-an-action/127403 "2008-01-28T22:52:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cleaner416](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d26b3c/32.png) [@cleaner416](https://www.ruby-forum.com/u/cleaner416)\
**Post date:** [January 28, 2008, 10:52pm UTC](https://www.ruby-forum.com/t/caching-only-certain-formats-xml-of-an-action/127403/1 "2008-01-28T22:52:09Z")

</div>

I’ve got a controller method that I’d like to cache … the problem is I  
only want to cache the XML output of a method. (This is for a number of  
reasons, including the fact that the feed of this action gets hit fairly  
often, but the html result does no and also contains other,  
user-specific info in the layout.)

In other words, I’m wondering how to do the following:

* * *

class MyController \< ApplicationContorller

caches\_action :index, :only\_format =\> :xml

def index

```
@items = Item.find( :all )
respond_to |format| do
  format.html # This should not be action cached
  format.xml # This should be action cached
end

```

end

end

* * *

Thanks!

---

<div class="post-metadata">

**Author:** ![cleaner416](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d26b3c/32.png) [@cleaner416](https://www.ruby-forum.com/u/cleaner416)\
**Post date:** [January 29, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/caching-only-certain-formats-xml-of-an-action/127403/2 "2008-01-29T17:02:08Z")

</div>

I suspect you’ll want to go beyond the pre-wired caching and use  
something like memcache where you’ll have a lot more control over what  
gets cached.

On Jan 28, 4:52 pm, Lance D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![cleaner416](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d26b3c/32.png) [@cleaner416](https://www.ruby-forum.com/u/cleaner416)\
**Post date:** [January 29, 2008, 5:12pm UTC](https://www.ruby-forum.com/t/caching-only-certain-formats-xml-of-an-action/127403/3 "2008-01-29T17:12:21Z")

</div>

AndyV wrote:

> I suspect you’ll want to go beyond the pre-wired caching and use  
> something like memcache where you’ll have a lot more control over what  
> gets cached.
> 
> On Jan 28, 4:52 pm, Lance D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks for the reply … but what effect would the fragment storage  
mechanism have on this functionality? AFAIK, file fragment storage has  
just as many options for namespace tinkering etc that memcache does.
