I should have made this more clear in the episode:
An instance variable only sticks around for a single request, so using the technique described will only benefit you if you need to call a method multiple times per request.
If you need to store a model or other data between requests, look into memcached.
I agree with Ryan Bates,and it is still useful for me.good tip!
我同意Ryan Bates,同时它依然对我有用.不错的技巧!
This is kindof automatically included in edge rails auto query caching.
@niko, right. This isn't as necessary in edge rails since the query is cached. However it will return a new instance of User every time so I still recommend caching it in an instance variable.
Hi,
Is it possible to subscribe to the old posts over itunes or only ones after episode 24?
Cheers,
Luke
@Luke, I went ahead and changed the feed so it will display all episodes. You should be able to download all episodes through iTunes in a day or so.
It appears the feed is missing episodes 20-23. If you can, can you add those to the iTunes feed?
@Brian, hmm, those episodes are showing up for me in iTunes Music Store. Is that where you're looking?
Ryan, yes, I am in the iTunes Music Store. In my iTunes I see all 1-55 listed except for 20-23. Given you're seeing them all I'm guessing now that I may have inadvertently deleted those from my iTunes (I did already view them once).
So an iTunes question for you or anyone -- is there a good way to restore a deleted iTunes entry?
since people are talking about it here...
I'd love all the back issues in iTunes as well. Right now, i'm only seeing episode 33 on. Did the feed get reset to only allow the last 30 episodes?
Thanks for such a great screencast!
@brooke, the full quality feed should show all episodes on iTunes. The iPod version doesn't - I'll try to fix that.
Can anyone explain this in more attractive way, so that I can easily uderstand the actual concept?
agree with saket...
would be great if there is a common scenario that demonstrates the benefit of using this technique...
I've just discovered Railscasts and thought I'd start at the first episode. Low and behold, absolute genius, I cut one of my request times in half by caching the return from my ldap lookup. Thanks, hoping to find many more gems as I work my way through the episodes.
This might sound like stupid question. I recently started learning php with sql. This looks like php coding but am not sure. It maybe little advance for me or maybe am just been stupid and there is previous tutorials.... I looked at #1 because I thouth it would be the easiest to get my head round. I kinda understand what is going on in this tutorial... but I am not sure where I would apply such a method? Thanks Ste
@Ste You might want to start with the Agile book titled "Agile Web Development with Rails". It makes a very nice beginner course for people who have done web development with other languages and frameworks.
Have a look.
Ryan, spectacular job on the Webcasts. Helps demystify the rails magic. This is a great tip but I am not clear on how it works? I thought instance variables only live as long as the routine is called. So every time you call current_user, isn't @current_user destroyed? Why isn't it? Is that rails or ruby at work? I assume rails.
thanks again for your dedication to the community
@mike b, in Ruby, instance variables stick around as long as the object exists. In Rails this controller object sticks around for the entire web request. So if you call current_user multiple times during that one request the User.find call will only happen once.
Where can I read the development.log in real time like it shows in the railcast? What I did was I open the development.log as text file each time I insert a new comment to read the latest log. I tried something with tail -f but that didn't work. I'm a newbie btw.
excellent this is want I needed to do to get images to display that ere uploaded using file_column
good tutorial, i had exactly that problem, with that instance variables it can improve the performance
The movie is damaged, could you upload again? Thanks!
Shawn, the movie is not damaged, but the url is wrong.
You can get the movie at:
http://media.railscasts.com/videos/001_caching_with_instance_variable.mov
Hi,
I have a doubt regarding caching in instance variables, forgive me if it is stupid.
What if I would need to catch more than 500 records..For example if I need to retreive all the employees of an organization..Would it be fine or is there any other suitable way to maximise performance?
I dont know why, but I'm not getting the result I was expecting.
I'm doing a project, when I know that the Id for one object is different in each environment. So the only thing I need is to keep the result of a query in a variable, and use it foreve on.
As a simple example, I tried to do
<script src="http://gist.github.com/99813.js"></script>
and displaying that on the view, and it has everytime different value.
What is my mistake? should I use memcached instead?
Thanks
Ooops! I tried to paste the following on Gist:
@now ||= Time.now # => or also @@now ||= Time.now
I already know the solution :)
I forgot to change the development config file (config/environments/development.rb). Here is only needed to change "config.cache_classes = false" to "true".
What if another thread updates your object in the database, while you are working with an old instance of the user? I think it is much better to cache these objects on the database server, or through a data access object. It really depends what your doing with the user, but it can get kind of messy caching stuff in this way.
Ryan...awesome.....Thank you....this will help many like me .....
good tutorial, i had exactly that problem, with that instance variables it can improve the performance
incredible ... This is very helpful at all, and you tell the detail. pleased to be able to visit here
@Brian, hmm, those episodes are showing up for me in iTunes Music Store. Is that where you're looking?
<A href="http://www.toptoys2trade.com/power-balance-wholesale-2-c-40/ "> power balance</A>
I should have made this more clear in the episode:
An instance variable only sticks around for a single request, so using the technique described will only benefit you if you need to call a method multiple times per request.
If you need to store a model or other data between requests, look into memcached.
we provide our buyers with an efficient and manageable procurement process covering every phase of the international supply chain and
streamlining trade channels. Also welcome wholesaling, feedback now!
I am a fanatic watch collection, especially the well-known watches, you also can do, click on my name!
I generally do not post in Blogs but your weblog forced me to, amazing work.. beautiful.
comes housed in a black plastic case with stainless steel lugs at each side. The black
wristband is nicely crafted from leather, and in case you plan on banging your new watch
around a bit, the display is protected by a durable, scratch-resistant mineral crystal
face.
<a href="http://www.powerbalancebracelet.org"><strong>Power Balance bracelet</strong></a> is a new technology that aids performance by using holograms embedded with frequencies that react positively with your body's energy to improve balance and strength.
<a href="http://www.powerbalancebracelet.org"><strong>Power Balance bracelet</strong></a> is a new technology that aids performance by using holograms embedded with frequencies that react positively with your body's energy to improve balance and strength.
This was a really useful episode, ROR really is awesome in that it lets you write code like that! Thanks for very good information. Excellent article that will provide the incentive and basis for my works.I wonder if I can mention the article as a bibliographic reference in my work. Thanks!
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets
This isn't as necessary in edge rails since the query is cached. However it will return a new instance of User every time so I still recommend caching it in an instance variable.
Nice post. My friend John told me about this blog some weeks ago but this is the first time I’m visting. I’ll undoubtedly be back.






