4 ms·
Rails, by default, uses '<table-name>-<id>-<updated_at>' for the cache key of an activerecord object. When an ActiveRecord object's `updated_at` column is touch
by cliftonk 14y ago
Rails, by default, uses '<table-name>-<id>-<updated_at>' for the cache key of an activerecord object. When an ActiveRecord object's `updated_at` column is touched, then all of it's cache keys will invalidate. I don't believe there's a default implementation for a collection.
There's significant network overhead to looping over a collection of objects and using cache blocks, so this gem appears to be a big win by using memcached's `multi_get` command.
- nate 14y agoThanks for answering that. Yep, there's a bit here: https://github.com/n8/multi_fetch_fragments/blob/master/lib/multi_fetch_fragments.rb https://github.com/n8/multi_fetch_fragments/blob/master/lib/... @collection.each do |item| key = @options[:cache].is_a?(Proc) ? @options[:cache].call(item) : item expanded_key = ActiveSupport::Cache.expand_cache_key(key) keys_to_collection_map[expanded_key] = item end Where I use ActiveSupport::Cache.expand_cache_key to create a key based on the item or the Proc passed in. And expand_cache_key does the work of coming up with the proper key. And activerecord objects have a default cache_key implemented that uses an updated_at timestamp if it's available: http://api.rubyonrails.org/classes/ActiveRecord/Integration.html#method-i-cache_key http://api.rubyonrails.org/classes/ActiveRecord/Integration....
- cliftonk 14y agoAnother thing to note is that typical memcached configurations have a short max key length (256 or 512 or something like that).