diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index 7ac6f35357..f3e4b8c13b 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -22,7 +22,7 @@ module ActiveSupport def write(name, value, options = nil) @guard.synchronize do super - @data[name] = value + @data[name] = value.freeze end end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index ce27b464f8..9ea9389448 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -120,4 +120,10 @@ class MemoryStoreTest < Test::Unit::TestCase def test_fetch_with_forced_cache_miss @cache.fetch('foo', :force => true) { 'bar' } end + + def test_store_objects_should_be_immutable + @cache.write('foo', 'bar') + assert_raise(ActiveSupport::FrozenObjectError) { @cache.read('foo').gsub!(/.*/, 'baz') } + assert_equal 'bar', @cache.read('foo') + end end