Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top