Module: SecondLevelCache::ActiveRecord::FinderMethods
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/second_level_cache/active_record/finder_methods.rb
Instance Method Summary collapse
Instance Method Details
#find_one_with_second_level_cache(id) ⇒ Object
TODO find_some github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/finder_methods.rb#L289-L309
Cacheable:
current_user.articles.where(:status => 1).visiable.find(params[:id])
Uncacheable:
Article.where("user_id = '1'").find(params[:id])
Article.where("user_id > 1").find(params[:id])
Article.where("articles.user_id = 1").find(prams[:id])
Article.where("user_id = 1 AND ...").find(params[:id])
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/second_level_cache/active_record/finder_methods.rb', line 28 def find_one_with_second_level_cache(id) return find_one_without_second_level_cache(id) unless second_level_cache_enabled? return find_one_without_second_level_cache(id) unless select_all_column? id = id.id if ActiveRecord::Base === id if cachable? if record = @klass.read_second_level_cache(id) return record end end if cachable_without_conditions? if record = @klass.read_second_level_cache(id) return record if where_match_with_cache?(where_values, record) end end record = find_one_without_second_level_cache(id) record.write_second_level_cache record end |