Memcached is an excellent cache store, and Dalli is the best way to interact with it through Ruby. Here I show various ways to use Memcached in a Rails app including how to set it up in production.
Nice RailsCast Ryan. Are you aware of any good write through caches for models. I'm aware of CacheMoney but it seems to be somewhat defunct for use with Rails 3.
This is a read through and write through plugin for ActiveRecord.
It can cache normal find query or has_one/belongs_to query, even find by other unique index column.
I would like to see something on the Russian doll technique that DHH often refers to too - perhaps with an update to the PJAX cast as well, as I think it's changed significantly since the episode that covered it.
Cool - about three weeks after this Railscast Ryan did go into the Russian doll technique, but actually did DHH's post one better. DHH outlines a manual versioning system for fragment content, since fragments can change without updating the models referenced within. As Ryan points out, that can get tricky.
In his Cache Digests Railscast, Ryan outlines how to hash and cache the full contents of a block, including the template and model contents. This eliminates the need for manual cache versioning and resolves some of the gotchas of the previous technique.
Ryan, in the video you mention that the category_name method may not increase performance due to multiple reads from memcached however, couldn't this be combated through the use of memoization as you show in episode 137?
The memoization is per-request based. It's good when you want to call the same (heavy) methods many times in a request lifetime (for instance, current_user).
Just a quick note if anyone else gets 'Dalli::RingError: No server available' (or it just says false when you try to write to the cache) I had run it as:
Why don't you use the include method to eager load the categories ? I think that would be a better fit than the caching you are showing. Great vid, though!
Nice RailsCast Ryan. Are you aware of any good write through caches for models. I'm aware of CacheMoney but it seems to be somewhat defunct for use with Rails 3.
Cheers
Paul
This is a read through and write through plugin for ActiveRecord.
It can cache normal find query or has_one/belongs_to query, even find by other unique index column.
https://github.com/csdn-dev/second_level_cache
Also check find_cache gem for thread safe model caching
https://github.com/mustafaturan/find_cache
http://rubygems.org/gems/find_cache
http://rubydoc.info/gems/find_cache/0.1.8/frames
It is simply an ActiveRecord object caching gem using Rails.cache methods.
Thanks Ryan!
I'm surprised you didn't show the russian dolls technique as exposed by 37signals few months ago (http://37signals.com/svn/posts/3113-how-key-based-cache-expiration-works).
It's a great video anyway, as always. ;)
Would like to see that as well.
Another great video Ryan!
I would like to see something on the Russian doll technique that DHH often refers to too - perhaps with an update to the PJAX cast as well, as I think it's changed significantly since the episode that covered it.
+1
Cool - about three weeks after this Railscast Ryan did go into the Russian doll technique, but actually did DHH's post one better. DHH outlines a manual versioning system for fragment content, since fragments can change without updating the models referenced within. As Ryan points out, that can get tricky.
In his Cache Digests Railscast, Ryan outlines how to hash and cache the full contents of a block, including the template and model contents. This eliminates the need for manual cache versioning and resolves some of the gotchas of the previous technique.
Ryan, is that a video rendering error at the end where you try to switch to "/-l" in vim? It looks like the video lags for a while.
Other than that, very nice intro to dalli!
Excellent episode Ryan. I really enjoy the fact that you're including deployment related information in your latest videos.
Do you know of a gem that is similar to dalli for redis caching (for persistence)?
Ryan, in the video you mention that the category_name method may not increase performance due to multiple reads from memcached however, couldn't this be combated through the use of memoization as you show in episode 137?
The memoization is per-request based. It's good when you want to call the same (heavy) methods many times in a request lifetime (for instance,
current_user).Just a quick note if anyone else gets 'Dalli::RingError: No server available' (or it just says false when you try to write to the cache) I had run it as:
memcached -l localhost
..and then it worked fine.
Why memcached and not redis, for example?
I have a question.
For the expression:
Rails.cache.fetch([:category, category_id, :name], expires_in: 5.minutes)
Why you didnt use :category_id here, why category_id do not need to symbolize, but category and name need to?
Why don't you use the include method to eager load the categories ? I think that would be a better fit than the caching you are showing. Great vid, though!
First sign in through GitHub to post a comment.