Class: Memcacheable::FetchHasOne
Instance Attribute Summary
#association, #object
Instance Method Summary
collapse
#cache_key, #class_name, #description, #initialize
Methods inherited from Fetcher
#debug, #fetch, #flush
Instance Method Details
#fetchable? ⇒ Boolean
3
4
5
|
# File 'lib/memcacheable/fetch_has_one.rb', line 3
def fetchable?
klass.respond_to?(:fetch_by) && klass.cached_indexes.include?(["#{class_name}_id".to_sym])
end
|
#find_on_cache_miss ⇒ Object
7
8
9
10
|
# File 'lib/memcacheable/fetch_has_one.rb', line 7
def find_on_cache_miss
criteria = { "#{class_name}_id" => object.id }
fetchable? ? klass.fetch_by(criteria) : object.send(association)
end
|
#klass ⇒ Object
12
13
14
|
# File 'lib/memcacheable/fetch_has_one.rb', line 12
def klass
@klass ||= association.to_s.camelize.constantize
end
|