Module: Memcacheable::ClassMethods
- Defined in:
- lib/memcacheable.rb
Instance Method Summary collapse
- #cache_belongs_to(association) ⇒ Object
- #cache_has_many(association) ⇒ Object
- #cache_has_one(association) ⇒ Object
- #cache_index(*fields) ⇒ Object
- #cache_method(*methods) ⇒ Object
- #fetch(id) ⇒ Object
- #fetch_by(*args) ⇒ Object
- #fetch_by!(*args) ⇒ Object
- #fetch_where(*args) ⇒ Object
Instance Method Details
#cache_belongs_to(association) ⇒ Object
34 35 36 37 38 |
# File 'lib/memcacheable.rb', line 34 def cache_belongs_to(association) define_method "fetch_#{association}" do FetchBelongsTo.new(self, association).fetch end end |
#cache_has_many(association) ⇒ Object
46 47 48 49 50 |
# File 'lib/memcacheable.rb', line 46 def cache_has_many(association) define_method "fetch_#{association}" do FetchHasMany.new(self, association).fetch end end |
#cache_has_one(association) ⇒ Object
40 41 42 43 44 |
# File 'lib/memcacheable.rb', line 40 def cache_has_one(association) define_method "fetch_#{association}" do FetchHasOne.new(self, association).fetch end end |
#cache_index(*fields) ⇒ Object
52 53 54 |
# File 'lib/memcacheable.rb', line 52 def cache_index(*fields) self.cached_indexes << fields.map(&:to_sym).sort end |
#cache_method(*methods) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/memcacheable.rb', line 56 def cache_method(*methods) methods.each do |method| define_method "fetch_#{method}" do |*args| FetchMethod.new(self, method, args).fetch end end end |
#fetch(id) ⇒ Object
64 65 66 |
# File 'lib/memcacheable.rb', line 64 def fetch(id) FetchOne.new(self, id).fetch end |
#fetch_by(*args) ⇒ Object
68 69 70 |
# File 'lib/memcacheable.rb', line 68 def fetch_by(*args) FetchBy.new(self, *args).fetch end |
#fetch_by!(*args) ⇒ Object
72 73 74 |
# File 'lib/memcacheable.rb', line 72 def fetch_by!(*args) fetch_by(*args) || raise(ActiveRecord::RecordNotFound) end |
#fetch_where(*args) ⇒ Object
76 77 78 |
# File 'lib/memcacheable.rb', line 76 def fetch_where(*args) FetchWhere.new(self, *args).fetch end |