RailsCasts Pro episodes are now free!

Learn more or hide this

railer aney's Profile

GitHub User: agindari

Site: https://www.change.org/p/jrandroidapps-improve-speed-of-android-apps-storage-server

Comments by railer aney

Avatar

2:34 to 3:03. Those two sentences makes no sense to me whatsoever. I've listened to it 10 times, and I can't tell what that line does. Sometimes the "foobar" terminology is unhelpful.

"So, if we pass a model object to the fetch method it's going to automatically use the cache key for that object, and we can supply multiple keys in an array and they will be joined together. So let's say we have some kind of property we want to compute on that article, we can execute that in a block here and this block will be executed just once when it sets the key and the next time we trigger it it won't trigger the block because the key is already set unless we change the Article model and that will change the key value."

Here is the line Ryan is describing:

Rails.cache.fetch([article, "foo"]) { 123 }

which returns:

=> 123

then he types it in the console again, and the same thing happens. What does this line do again? And what does "123" do? And how do I know that it isn't triggered the second time?

How is any fetching done when nothing in the cache had been set yet? I am really missing something on this one.