<?xml version="1.0" encoding="UTF-8"?>
<ticket>
  <assigned-user-id type="integer">424</assigned-user-id>
  <attachments-count type="integer">1</attachments-count>
  <closed type="boolean">true</closed>
  <created-at type="datetime">2008-08-11T16:00:05+01:00</created-at>
  <creator-id type="integer">7840</creator-id>
  <milestone-due-on type="datetime" nil="true"></milestone-due-on>
  <milestone-id type="integer">9903</milestone-id>
  <number type="integer">799</number>
  <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
  <priority type="integer">260</priority>
  <project-id type="integer">8994</project-id>
  <raw-data type="binary" nil="true" encoding="base64"></raw-data>
  <state>resolved</state>
  <tag>activesupport patch</tag>
  <title>MemoryStore cache contents should be immutable</title>
  <updated-at type="datetime">2008-08-20T01:21:41+01:00</updated-at>
  <user-id type="integer">424</user-id>
  <user-name>Joshua Peek</user-name>
  <creator-name>Jim Lindley</creator-name>
  <assigned-user-name>Joshua Peek</assigned-user-name>
  <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
  <milestone-title>2.x</milestone-title>
  <original-body>This was a side issue to ticket #785. Splitting out into it's own ticket for further discussion. MemoryStore cache contents can be altered by changing fetched objects outside of the cache.

&quot;[T]he existing MemoryStore implementation is faulty because changes made to an object afterwards effect the cache. This happens in production as well. I don't know of any other caching technique that behaves this way, and I think it's one of the core problems with MemoryStore itself.&quot; (As explained by Ryan Bates in #785)

&lt;code&gt;
cache = ActiveSupport::Cache.lookup_store(:memory_store)
h = {:a =&gt; 1}
cache.write('foo', h)
h[:a] = 2
cache.read('foo')[:a] # =&gt; 2
&lt;code&gt;

The proposal to fix this issue was to dup objects on write and outgoing as fetched, when possible. (Nil, False, etc, can't be dupped).</original-body>
  <latest-body>This was a side issue to ticket #785. Splitting out into it's own ticket for further discussion. MemoryStore cache contents can be altered by changing fetched objects outside of the cache.

&quot;[T]he existing MemoryStore implementation is faulty because changes made to an object afterwards effect the cache. This happens in production as well. I don't know of any other caching technique that behaves this way, and I think it's one of the core problems with MemoryStore itself.&quot; (As explained by Ryan Bates in #785)

&lt;code&gt;
cache = ActiveSupport::Cache.lookup_store(:memory_store)
h = {:a =&gt; 1}
cache.write('foo', h)
h[:a] = 2
cache.read('foo')[:a] # =&gt; 2
&lt;code&gt;

The proposal to fix this issue was to dup objects on write and outgoing as fetched, when possible. (Nil, False, etc, can't be dupped).</latest-body>
  <original-body-html>&lt;div&gt;&lt;p&gt;This was a side issue to ticket &lt;a href=&quot;/projects/8994/tickets/785&quot; title=&quot;Ticket #785&quot;&gt;#785&lt;/a&gt;. Splitting out into it's own ticket for further discussion. MemoryStore cache contents can be altered by changing fetched objects outside of the cache.&lt;/p&gt;

&lt;p&gt;&quot;[T]he existing MemoryStore implementation is faulty because changes made to an object afterwards effect the cache. This happens in production as well. I don't know of any other caching technique that behaves this way, and I think it's one of the core problems with MemoryStore itself.&quot; (As explained by Ryan Bates in &lt;a href=&quot;/projects/8994/tickets/785&quot; title=&quot;Ticket #785&quot;&gt;#785&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;cache = ActiveSupport::Cache.lookup_store(:memory_store)
h = {:a =&gt; 1}
cache.write('foo', h)
h[:a] = 2
cache.read('foo')[:a] # =&gt; 2&lt;/p&gt;

&lt;p&gt;The proposal to fix this issue was to dup objects on write and outgoing as fetched, when possible. (Nil, False, etc, can't be dupped).&lt;/p&gt;&lt;/div&gt;</original-body-html>
  <versions type="array">
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>This was a side issue to ticket #785. Splitting out into it's own ticket for further discussion. MemoryStore cache contents can be altered by changing fetched objects outside of the cache.

&quot;[T]he existing MemoryStore implementation is faulty because changes made to an object afterwards effect the cache. This happens in production as well. I don't know of any other caching technique that behaves this way, and I think it's one of the core problems with MemoryStore itself.&quot; (As explained by Ryan Bates in #785)

@@@ ruby
cache = ActiveSupport::Cache.lookup_store(:memory_store)
h = {:a =&gt; 1}
cache.write('foo', h)
h[:a] = 2
cache.read('foo')[:a] # =&gt; 2
@@@

The proposal to fix this issue was to dup objects on write and outgoing as fetched, when possible. (Nil, False, etc, can't be dupped).</body>
      <body-html>&lt;div&gt;&lt;p&gt;This was a side issue to ticket &lt;a href=&quot;/projects/8994/tickets/785&quot; title=&quot;Ticket #785&quot;&gt;#785&lt;/a&gt;. Splitting out into it's own ticket for further discussion. MemoryStore cache contents can be altered by changing fetched objects outside of the cache.&lt;/p&gt;

&lt;p&gt;&quot;[T]he existing MemoryStore implementation is faulty because changes made to an object afterwards effect the cache. This happens in production as well. I don't know of any other caching technique that behaves this way, and I think it's one of the core problems with MemoryStore itself.&quot; (As explained by Ryan Bates in &lt;a href=&quot;/projects/8994/tickets/785&quot; title=&quot;Ticket #785&quot;&gt;#785&lt;/a&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
cache = ActiveSupport::Cache.lookup_store(:memory_store)
h = {:a =&amp;gt; 1}
cache.write('foo', h)
h[:a] = 2
cache.read('foo')[:a] # =&amp;gt; 2
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The proposal to fix this issue was to dup objects on write and outgoing as fetched, when possible. (Nil, False, etc, can't be dupped).&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T17:25:37+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activesupport</tag>
      <title>MemoryStore cache contents should be dup'd..</title>
      <updated-at type="datetime">2008-08-11T17:25:37+01:00</updated-at>
      <user-id type="integer">7840</user-id>
      <user-name>Jim Lindley</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>Aaargh, getting the code formatting wrong. Trying again, with Ryan's example.

Existing behaviour:

@@@ ruby

    cache = ActiveSupport::Cache.lookup_store(:memory_store) 
    h = {:a =&gt; 1} 
    cache.write('foo', h) 
    h[:a] = 2 cache.read('foo')[:a] # =&gt; 2

@@@</body>
      <body-html>&lt;div&gt;&lt;p&gt;Aaargh, getting the code formatting wrong. Trying again, with Ryan's example.&lt;/p&gt;

&lt;p&gt;Existing behaviour:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;

    cache = ActiveSupport::Cache.lookup_store(:memory_store)
    h = {:a =&amp;gt; 1}
    cache.write('foo', h)
    h[:a] = 2 cache.read('foo')[:a] # =&amp;gt; 2

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T16:02:16+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activesupport</tag>
      <title>MemoryStore cache contents should be dup'd..</title>
      <updated-at type="datetime">2008-08-11T16:02:16+01:00</updated-at>
      <user-id type="integer">7840</user-id>
      <user-name>Jim Lindley</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>As determined in the other ticket (#785), dup is an efficient way to resolve this issue. Here's an attachment which just adds this behavior.

BTW, I think it's possible for you to update the original ticket and fix the formatting so the rest of the page isn't monospace. Thanks.</body>
      <body-html>&lt;div&gt;&lt;p&gt;As determined in the other ticket (#785), dup is an efficient way to resolve this issue. Here's an attachment which just adds this behavior.&lt;/p&gt;

&lt;p&gt;BTW, I think it's possible for you to update the original ticket and fix the formatting so the rest of the page isn't monospace. Thanks.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T16:23:41+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- 
:tag: activesupport
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activesupport bug patch</tag>
      <title>MemoryStore cache contents should be dup'd..</title>
      <updated-at type="datetime">2008-08-11T16:23:41+01:00</updated-at>
      <user-id type="integer">5701</user-id>
      <user-name>Ryan Bates</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Doesn't look like I can edit the original. Wish there was a preview button. Stuck with monospaced.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Doesn't look like I can edit the original. Wish there was a preview button. Stuck with monospaced.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T16:34:01+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activesupport bug patch</tag>
      <title>MemoryStore cache contents should be dup'd..</title>
      <updated-at type="datetime">2008-08-11T16:34:01+01:00</updated-at>
      <user-id type="integer">7840</user-id>
      <user-name>Jim Lindley</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>There should be an &quot;Edit Ticket&quot; link in the blue bar at the top. At least that's available on my tickets.</body>
      <body-html>&lt;div&gt;&lt;p&gt;There should be an &quot;Edit Ticket&quot; link in the blue bar at the top. At least that's available on my tickets.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T16:51:17+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activesupport bug patch</tag>
      <title>MemoryStore cache contents should be dup'd..</title>
      <updated-at type="datetime">2008-08-11T16:51:17+01:00</updated-at>
      <user-id type="integer">5701</user-id>
      <user-name>Ryan Bates</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Not sure if this is a show stopper but the following test (inserted in MemoryStoreTest) fails:

@@@ ruby
  class SimpleClass
    attr_accessor :value
    def initialize(value)
      @value = value
    end
  end
  
  def test_instance_variable_duping
    instance = SimpleClass.new(SimpleClass.new(&quot;Pass&quot;))
    @cache.write(&quot;instance&quot;, instance)
    instance.value.value = &quot;FAIL!&quot;
    assert_equal &quot;Pass&quot;,  @cache.read(&quot;instance&quot;).value.value
  end
@@@

No simple way around this, but it could be an argument in favour of serializing it despite the overhead.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Not sure if this is a show stopper but the following test (inserted in MemoryStoreTest) fails:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
  class SimpleClass
    attr_accessor :value
    def initialize(value)
      @value = value
    end
  end

  def test_instance_variable_duping
    instance = SimpleClass.new(SimpleClass.new(&amp;quot;Pass&amp;quot;))
    @cache.write(&amp;quot;instance&amp;quot;, instance)
    instance.value.value = &amp;quot;FAIL!&amp;quot;
    assert_equal &amp;quot;Pass&amp;quot;,  @cache.read(&amp;quot;instance&amp;quot;).value.value
  end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;No simple way around this, but it could be an argument in favour of serializing it despite the overhead.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T16:57:08+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activesupport bug patch</tag>
      <title>MemoryStore cache contents should be dup'd..</title>
      <updated-at type="datetime">2008-08-11T16:57:08+01:00</updated-at>
      <user-id type="integer">28420</user-id>
      <user-name>Tom Lea</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Ryan, I get those edit links on my own Lighthouse projects, but not when I'm logged in here at the Rails project.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Ryan, I get those edit links on my own Lighthouse projects, but not when I'm logged in here at the Rails project.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T17:04:31+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activesupport bug patch</tag>
      <title>MemoryStore cache contents should be dup'd..</title>
      <updated-at type="datetime">2008-08-11T17:04:31+01:00</updated-at>
      <user-id type="integer">7840</user-id>
      <user-name>Jim Lindley</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Fixed thanks to Rick and Will - the edit link shows up for me now.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Fixed thanks to Rick and Will - the edit link shows up for me now.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T19:07:32+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>activesupport bug patch</tag>
      <title>MemoryStore cache contents should be dup'd..</title>
      <updated-at type="datetime">2008-08-11T19:07:32+01:00</updated-at>
      <user-id type="integer">7840</user-id>
      <user-name>Jim Lindley</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name nil="true"></assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">424</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>I'm of the opinion that all cache store should be immutable. So freeze every object on write. If you need a mutable copy, dup at your own expense.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I'm of the opinion that all cache store should be immutable. So freeze every object on write. If you need a mutable copy, dup at your own expense.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T21:01:50+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- 
:tag: activesupport bug patch
:state: new
:assigned_user: 
:title: MemoryStore cache contents should be dup'd..
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>open</state>
      <tag>activesupport patch</tag>
      <title>MemoryStore cache contents should be immutable</title>
      <updated-at type="datetime">2008-08-11T21:01:50+01:00</updated-at>
      <user-id type="integer">424</user-id>
      <user-name>Joshua Peek</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name>Joshua Peek</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">424</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>Requiring all objects sent to cache be immutable can really complicate the code. For example:

@@@ ruby
all_cached = Rails.cache.read('Recipe.all')
if all_cached.nil?
  all = Recipe.all
  Rails.cache.write('Recipe.all', all.dup.freeze)
else
  all = all_cached.dup
end

# vs.

all = Rails.cache.fetch('Recipe.all') { Recipe.all }
@@@

To me this seems like something the framework should do, especially considering we have the convenient &quot;fetch&quot; method built in.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Requiring all objects sent to cache be immutable can really complicate the code. For example:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
all_cached = Rails.cache.read('Recipe.all')
if all_cached.nil?
  all = Recipe.all
  Rails.cache.write('Recipe.all', all.dup.freeze)
else
  all = all_cached.dup
end

# vs.

all = Rails.cache.fetch('Recipe.all') { Recipe.all }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To me this seems like something the framework should do, especially considering we have the convenient &quot;fetch&quot; method built in.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-11T21:52:01+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>open</state>
      <tag>activesupport patch</tag>
      <title>MemoryStore cache contents should be immutable</title>
      <updated-at type="datetime">2008-08-11T21:52:01+01:00</updated-at>
      <user-id type="integer">5701</user-id>
      <user-name>Ryan Bates</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name>Joshua Peek</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">424</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>@Ryan I meant to have Store#write call freeze on the the given value. freeze should also be called on the retrieved value as well. Requiring &quot;frozen?&quot; to be true is silly as you just demonstrated :)

You never want to modify objects in the cache store.</body>
      <body-html>&lt;div&gt;&lt;p&gt;@Ryan I meant to have Store#write call freeze on the the given value. freeze should also be called on the retrieved value as well. Requiring &quot;frozen?&quot; to be true is silly as you just demonstrated :)&lt;/p&gt;

&lt;p&gt;You never want to modify objects in the cache store.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-13T01:45:23+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>open</state>
      <tag>activesupport patch</tag>
      <title>MemoryStore cache contents should be immutable</title>
      <updated-at type="datetime">2008-08-13T01:45:23+01:00</updated-at>
      <user-id type="integer">424</user-id>
      <user-name>Joshua Peek</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name>Joshua Peek</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">424</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>If the cache store calls freeze on write then the developer has to ensure every mutable object is duplicated before passing it to cache, correct? This results in 7 lines instead of 1 as demonstrated. Is there a better solution which will keep the code simple for developers?</body>
      <body-html>&lt;div&gt;&lt;p&gt;If the cache store calls freeze on write then the developer has to ensure every mutable object is duplicated before passing it to cache, correct? This results in 7 lines instead of 1 as demonstrated. Is there a better solution which will keep the code simple for developers?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-13T17:45:03+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>open</state>
      <tag>activesupport patch</tag>
      <title>MemoryStore cache contents should be immutable</title>
      <updated-at type="datetime">2008-08-13T17:45:03+01:00</updated-at>
      <user-id type="integer">5701</user-id>
      <user-name>Ryan Bates</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name>Joshua Peek</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">424</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>As I understand it all Caches serialize (Martial or YAML) into the store, unless :raw is set. This is well tested and expected. Memory store should be no different.

If we dup in and dup out for :raw (which is only expected to be able to cache strings anyway), we fix the mutable cached values issue. If we Martial none raw values, everything works as expected and fix #785.

The next question is how the performance is v.s. other stores (mainly FileStore, it being the main competitor to MemoryStore in my mind) with and without martialing.

Thoughts?</body>
      <body-html>&lt;div&gt;&lt;p&gt;As I understand it all Caches serialize (Martial or YAML) into the store, unless :raw is set. This is well tested and expected. Memory store should be no different.&lt;/p&gt;

&lt;p&gt;If we dup in and dup out for :raw (which is only expected to be able to cache strings anyway), we fix the mutable cached values issue. If we Martial none raw values, everything works as expected and fix &lt;a href=&quot;/projects/8994/tickets/785&quot; title=&quot;Ticket #785&quot;&gt;#785&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The next question is how the performance is v.s. other stores (mainly FileStore, it being the main competitor to MemoryStore in my mind) with and without martialing.&lt;/p&gt;

&lt;p&gt;Thoughts?&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-13T18:51:16+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>open</state>
      <tag>activesupport patch</tag>
      <title>MemoryStore cache contents should be immutable</title>
      <updated-at type="datetime">2008-08-13T18:51:16+01:00</updated-at>
      <user-id type="integer">28420</user-id>
      <user-name>Tom Lea</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name>Joshua Peek</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer">424</assigned-user-id>
      <attachments-count type="integer">1</attachments-count>
      <body>http://github.com/rails/rails/commit/5de340e79f1d11973b7c7bbec82f320fc92b9c99</body>
      <body-html>&lt;div&gt;&lt;p&gt;&lt;a href=&quot;http://github.com/rails/rails/commit/5de340e79f1d11973b7c7bbec82f320fc92b9c99&quot;&gt;http://github.com/rails/rails/co...&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2008-08-20T01:21:41+01:00</created-at>
      <creator-id type="integer">7840</creator-id>
      <diffable-attributes type="yaml">--- 
:state: open
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">799</number>
      <permalink>memorystore-cache-contents-should-be-dup-d</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>resolved</state>
      <tag>activesupport patch</tag>
      <title>MemoryStore cache contents should be immutable</title>
      <updated-at type="datetime">2008-08-20T01:21:41+01:00</updated-at>
      <user-id type="integer">424</user-id>
      <user-name>Joshua Peek</user-name>
      <creator-name>Jim Lindley</creator-name>
      <assigned-user-name>Joshua Peek</assigned-user-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/799</url>
      <milestone-title>2.x</milestone-title>
    </version>
  </versions>
  <attachments type="array">
    <attachment type="Attachment">
      <code>fbf2ea1cc340811df4cca1838f04527ca2f0095e</code>
      <content-type>text/plain</content-type>
      <created-at type="datetime">2008-08-11T16:23:40+01:00</created-at>
      <filename>dup_in_memory_store.diff</filename>
      <height type="integer" nil="true"></height>
      <id type="integer">38400</id>
      <size type="integer">2003</size>
      <uploader-id type="integer">5701</uploader-id>
      <width type="integer" nil="true"></width>
      <url>http://rails.lighthouseapp.com/attachments/38400/dup_in_memory_store.diff</url>
    </attachment>
  </attachments>
</ticket>
