Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cache_all_output vs fragment caching #281

Closed
axsuul opened this issue Jul 5, 2012 · 2 comments
Closed

cache_all_output vs fragment caching #281

axsuul opened this issue Jul 5, 2012 · 2 comments
Labels

Comments

@axsuul
Copy link

axsuul commented Jul 5, 2012

Hi, sorry if my question sounds noobish but what is the difference between the config option cache_all_output vs. having to do something like

cache @user

in a template? Does cache_all_output save you from having to do this in each template and enable caching for every template? From my tests, it doesn't seem so. So what does cache_all_output do exactly?

@databyte
Copy link
Collaborator

databyte commented Jul 5, 2012

cache_all_output does indeed cache all templates without having to explicitly set a cache_key but the assumption is that the cache_key is the object. You still have to have caching enabled in Rails and setup the proper storage as you normally would for Rails caching. You can see the cached hits in the Rails log and by the lack of database queries that may be triggered from within the template itself.

I go into more detail about cache_all_output here. They key part is:

The assumption when using cache_all_output is that when you partial a user - you'll always output the exact same user. If you want to output a different "template", you specify a different object name via :object_name => :different_name.

Meaning that if you cache user.cache_key under one of your templates, that's the cache entry that's going to be used for all templates matching user.cache_key. Every representation of user is a singleton of user.

If you want to represent the user twice, you can use:

child :user => :user do
  extends "users/user"
end

child :user => :user_with_email do
  extends "users/secure_user"
end

@databyte
Copy link
Collaborator

If you have any other questions, you can reopen it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants