Module: Cache::Object::ActiveRecord::ClassMethods
- Defined in:
- lib/cache/object/active_record.rb
Instance Method Summary collapse
- #_load(args) ⇒ Object
- #fetch_all(ids) ⇒ Object
- #find(*args) ⇒ Object
- #find_by_id(id) ⇒ Object
- #object_cache_on(*attrs) ⇒ Object
Instance Method Details
#_load(args) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/cache/object/active_record.rb', line 54 def _load(args) attributes = Marshal.load(args) object = allocate object.load_from_cache(attributes) object end |
#fetch_all(ids) ⇒ Object
73 74 75 |
# File 'lib/cache/object/active_record.rb', line 73 def fetch_all(ids) Cache::Object::MultiGet.new(self).fetch_all(ids) end |
#find(*args) ⇒ Object
61 62 63 64 65 |
# File 'lib/cache/object/active_record.rb', line 61 def find(*args) Cache::Object.adapter.fetch(self, *args[0]) do super(*args) end end |
#find_by_id(id) ⇒ Object
67 68 69 70 71 |
# File 'lib/cache/object/active_record.rb', line 67 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
77 78 79 80 81 82 83 84 85 |
# File 'lib/cache/object/active_record.rb', line 77 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 |