Class: Memcacheable::FetchHasOne

Inherits:
FetchAssociation show all
Defined in:
lib/memcacheable/fetch_has_one.rb

Instance Attribute Summary

Attributes inherited from FetchAssociation

#association, #object

Instance Method Summary collapse

Methods inherited from FetchAssociation

#cache_key, #class_name, #description, #initialize

Methods inherited from Fetcher

#debug, #fetch, #flush

Constructor Details

This class inherits a constructor from Memcacheable::FetchAssociation

Instance Method Details

#fetchable?Boolean

Returns:

  • (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_missObject



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

#klassObject



12
13
14
# File 'lib/memcacheable/fetch_has_one.rb', line 12

def klass
  @klass ||= association.to_s.camelize.constantize
end