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

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

Instance Method Summary collapse

Instance Method Details

#_load(args) ⇒ Object



67
68
69
70
71
72
# File 'lib/cache/object/active_record.rb', line 67

def _load(args)
  attributes = Marshal.load(args)
  object = allocate
  object.load_from_cache(attributes)
  object
end

#fetch_all(ids) ⇒ Object



86
87
88
# File 'lib/cache/object/active_record.rb', line 86

def fetch_all(ids)
  Cache::Object::MultiGet.new(self).fetch_all(ids)
end

#find(*args) ⇒ Object



74
75
76
77
78
# File 'lib/cache/object/active_record.rb', line 74

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

#find_by_id(id) ⇒ Object



80
81
82
83
84
# File 'lib/cache/object/active_record.rb', line 80

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

#object_cache_include(*accessors) ⇒ Object



90
91
92
# File 'lib/cache/object/active_record.rb', line 90

def object_cache_include(*accessors)
  self._object_cache_include << accessors
end

#object_cache_on(*attrs) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/cache/object/active_record.rb', line 94

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