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_include(*accessors) ⇒ Object
- #object_cache_on(*attrs) ⇒ Object
Instance Method Details
#_load(args) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/cache/object/active_record.rb', line 84 def _load(args) attributes = Marshal.load(args) object = allocate object.load_from_cache(attributes) object end |
#fetch_all(ids) ⇒ Object
103 104 105 |
# File 'lib/cache/object/active_record.rb', line 103 def fetch_all(ids) Cache::Object::MultiGet.new(self).fetch_all(ids) end |
#find(*args) ⇒ Object
91 92 93 94 95 |
# File 'lib/cache/object/active_record.rb', line 91 def find(*args) Cache::Object.adapter.fetch(self, *args[0]) do super(*args) end end |
#find_by_id(id) ⇒ Object
97 98 99 100 101 |
# File 'lib/cache/object/active_record.rb', line 97 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
107 108 109 |
# File 'lib/cache/object/active_record.rb', line 107 def object_cache_include(*accessors) self._object_cache_include << accessors end |
#object_cache_on(*attrs) ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/cache/object/active_record.rb', line 111 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 |