diff --git a/lib/second_level_cache.rb b/lib/second_level_cache.rb index 989ebc8..c069c70 100644 --- a/lib/second_level_cache.rb +++ b/lib/second_level_cache.rb @@ -26,7 +26,11 @@ def acts_as_cached(options = {}) end def second_level_cache_enabled? - !!@second_level_cache_enabled + if defined?(Rails) + !!@second_level_cache_enabled && ::Rails.application.config.cache_classes + else + !!@second_level_cache_enabled + end end def without_second_level_cache diff --git a/lib/second_level_cache/active_record/has_one_association.rb b/lib/second_level_cache/active_record/has_one_association.rb index 211a438..34c1742 100644 --- a/lib/second_level_cache/active_record/has_one_association.rb +++ b/lib/second_level_cache/active_record/has_one_association.rb @@ -12,6 +12,7 @@ module HasOneAssociation def find_target_with_second_level_cache return find_target_without_second_level_cache unless association_class.second_level_cache_enabled? + return find_target_without_second_level_cache if self.class == ::ActiveRecord::Associations::HasOneThroughAssociation cache_record = association_class.fetch_by_uniq_key(owner[reflection.active_record_primary_key], reflection.foreign_key) return cache_record.tap{|record| set_inverse_instance(record)} if cache_record