So in fact it seems that i just learned something.
If i create an instance variable in my action
@last_posts = User.first.get_last_posts
but doesn't use this variable nowhere else in my action or view
then only the User.first call will be triggered to get the user so i can retrieve his last posts.
Then the user.get_last_posts call won't be triggered because the result of this request is never used in the rest off my app.
So, to be clear, when i define an instance variable, the object is keep in cache, and if it's needed later in the controller/view code, then the method associated i.e get_last _post is processed
am i right ?
Should i go see a railcast which perfectly explain this behavior ? :)
Hi i have a strange issue with fragment caching with rails 3.2 & memcached as a cache store.
I use framgent caching in a partial and loop on a instance variable @recent_posts in my index view.
The problem, i think, is in my index action.
I didn't change anything to my code, so normally,my partial should be cached but the sql request that get my @recent_post should be processed.
Or it appears that the first request trigger the sql but the requests after wont.
To be a little more precise, my @recent_posts is defined by something like that.
@recent_post = SomeModel.first.get_last_posts.
And it appear that the SomeModel.first call is triggered every time but only the .get_last_post sql request won't be processed for the 2+ request...
and the answer
http://asciicasts.com/episodes/202-active-record-queries-in-rails-3
see lazy query
So in fact it seems that i just learned something.
If i create an instance variable in my action
@last_posts = User.first.get_last_posts
but doesn't use this variable nowhere else in my action or view
then only the User.first call will be triggered to get the user so i can retrieve his last posts.
Then the user.get_last_posts call won't be triggered because the result of this request is never used in the rest off my app.
So, to be clear, when i define an instance variable, the object is keep in cache, and if it's needed later in the controller/view code, then the method associated i.e get_last _post is processed
am i right ?
Should i go see a railcast which perfectly explain this behavior ? :)
Hi i have a strange issue with fragment caching with rails 3.2 & memcached as a cache store.
I use framgent caching in a partial and loop on a instance variable @recent_posts in my index view.
The problem, i think, is in my index action.
I didn't change anything to my code, so normally,my partial should be cached but the sql request that get my @recent_post should be processed.
Or it appears that the first request trigger the sql but the requests after wont.
To be a little more precise, my @recent_posts is defined by something like that.
@recent_post = SomeModel.first.get_last_posts.
And it appear that the SomeModel.first call is triggered every time but only the .get_last_post sql request won't be processed for the 2+ request...
Any though ?