Module: Cash::Finders::ClassMethods

Defined in:
lib/cash/finders.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(active_record_class) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/cash/finders.rb', line 10

def self.extended(active_record_class)
  class << active_record_class
    alias_method_chain :find_every, :cache
    alias_method_chain :find_from_ids, :cache
    alias_method_chain :calculate, :cache
  end
end

Instance Method Details

#calculate_with_cache(operation, column_name, options = {}) ⇒ Object

User.count(:all), User.count, User.sum(…)



41
42
43
44
45
46
47
# File 'lib/cash/finders.rb', line 41

def calculate_with_cache(operation, column_name, options = {})
  if cacheable?
    Query::Calculation.perform(self, operation, column_name, options, scope(:find))
  else
    calculate_without_cache(operation, column_name, options)
  end
end

#find_every_with_cache(options) ⇒ Object

User.find(:first, …), User.find_by_foo(…), User.find(:all, …), User.find_all_by_foo(…)



23
24
25
26
27
28
29
# File 'lib/cash/finders.rb', line 23

def find_every_with_cache(options)
  if cacheable?
    Query::Select.perform(self, options, scope(:find))
  else
    find_every_without_cache(options)
  end
end

#find_from_ids_with_cache(ids, options) ⇒ Object

User.find(1), User.find(1, 2, 3), User.find([1, 2, 3]), User.find([])



32
33
34
35
36
37
38
# File 'lib/cash/finders.rb', line 32

def find_from_ids_with_cache(ids, options)
  if cacheable?
    Query::PrimaryKey.perform(self, ids, options, scope(:find))
  else
    find_from_ids_without_cache(ids, options)
  end
end

#without_cache(&block) ⇒ Object



18
19
20
# File 'lib/cash/finders.rb', line 18

def without_cache(&block)
  with_scope(:find => {:readonly => true}, &block)
end