3 ms·
Thanks 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/
by nate 14y ago
Thanks 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).