diff --git a/lib/garner/cache/identity.rb b/lib/garner/cache/identity.rb index 131d433..147ed79 100644 --- a/lib/garner/cache/identity.rb +++ b/lib/garner/cache/identity.rb @@ -11,8 +11,8 @@ def initialize(ruby_context = nil) @key_hash = {} # Set up options hash with defaults - @options_hash = Garner.config.global_cache_options || {} - @options_hash.merge!(expires_in: Garner.config.expires_in) + @options_hash = Garner.config.global_cache_options.dup || {} + @options_hash[:expires_in] ||= Garner.config.expires_in end def fetch(&block) diff --git a/spec/garner/cache/identity_spec.rb b/spec/garner/cache/identity_spec.rb index bc2e4db..682024b 100644 --- a/spec/garner/cache/identity_spec.rb +++ b/spec/garner/cache/identity_spec.rb @@ -6,6 +6,13 @@ expect(subject.options_hash[:foo]).to eq 'bar' end + it 'includes Garner.config.global_cache_options[:expires_in]' do + Garner.configure do |config| + config.global_cache_options = { expires_in: 5.minutes } + end + subject.options_hash[:expires_in].should eq 5.minutes + end + it 'includes Garner.config.expires_in' do Garner.configure { |config| config.expires_in = 5.minutes } expect(subject.options_hash[:expires_in]).to eq 5.minutes