1

I have build an application using inherited_resource plugin and its ready to go into production.

Now I am looking at ways to implement caching for the same application. As I have some fragments of the page which are dependent on the current_user I am going to use the fragment caching mechanism.

Can someone please provide me with the a pointer or resource which helps in implementing fragment caching for inherited_resource based views and controllers?

Thanks, Ajay Kumar G

Aj Gu
  • 1,509
  • 9
  • 12

1 Answers1

0

I don't use inherited_resources, but my understanding is that it's just a shortcut for controllers. Your views should just be standard, in which case you can use fragment caching as described in the Rails Guide at http://guides.rubyonrails.org/caching_with_rails.html#fragment-caching

Have you tried that? If that doesn't work show us what your views look like.


edit: response to the comment.

Ah okay, so in general if you are using fragment caching it doesn't make sense not to call the controller action, because you won't have any variables set, and if there are no variables then why are you not using page caching?

In order to prevent queries from firing, ActiveRecord 3.0 with arel is your friend. For instance, if you put @posts = Post.where(:published => true) in your action then it will not be called until you call @posts.each in the view, so if you put that inside the cache block it will never be called. I'm not sure what inherited_resources does by default, but given that it's written by José Valim I imagine he would be using that feature of ActiveRecord by default, if not it is easy to customize. You can test it out by turning on caching for your development environment and watching the logs to see what queries are being fired.

gtd
  • 16,956
  • 6
  • 49
  • 65
  • Ya you are right I am using fragment caching to cache the views. But there is no way I could stop the controller code (and DB queries) from being executed when a request hits the server. What I am looking for is an elegant way in which I could stop the inherited_resource controllers code being executed based on the caching – Aj Gu May 29 '11 at 16:56
  • I guess you are right. ARel is the key here. I will post back once I confirm it. – Aj Gu May 30 '11 at 01:18