Module: Cache::Object::ActiveRecord::ClassMethods

Defined in:
lib/cache/object/active_record.rb

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object



33
34
35
36
37
# File 'lib/cache/object/active_record.rb', line 33

def find(*args)
  Cache::Object.adapter.fetch(self, *args[0]) do
    super(*args)
  end
end

#find_by_id(id) ⇒ Object



39
40
41
42
43
# File 'lib/cache/object/active_record.rb', line 39

def find_by_id(id)
  Cache::Object.adapter.fetch(self, id) do
    where(self.primary_key => id).first
  end
end

#object_cache_on(*attrs) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/cache/object/active_record.rb', line 45

def object_cache_on(*attrs)
  self._object_cache_attr_mappings << attrs
  define_singleton_method("find_by_#{attrs.join('_and_')}") do |*args|
    attributes = Hash[attrs.zip(args)]
    Cache::Object.adapter.fetch_mapping(self, attributes) do
      super(*args)
    end
  end
end