title: Objects from cache in PlayFramework seem to be the original objects?
body: <p>Another PlayFramework 2.x (2.5 to be specific) related question regarding caching. Play uses EhCache, but I <strong>THINK</strong> this is a Play-question, not an EhCache question - but I might be wrong.</p>
  
  <p>So I fetch objects from the cache. In this example, I am getting menu items from a database and then I am highlighting the current menu item. This is the code:</p>
  
  <pre><code>List&lt;Menu&gt; menuitems = cache.getOrElse("menu", () -&gt; getMenuitemsFromDatabase(), DURATION_14_DAYS);
  for (Menu menuitem : menuitems) {
      if (menuitem.getUrl().equals(request.uri())) {
          menuitem.setHighlighted(true);
          break;
      }
  }
  </code></pre>
  
  <p>Problem is, I always get the same object from the cache. With same object I really mean the same object from memory. I guess it is stored in some hashmap in memory and I am fetching the same entry each time.</p>
  
  <p>This means, when I browse to two websites, then the current and the previous menu item is highlighted. And obviously it gets worse, if I browse to more sites.</p>
  
  <p>What I expect (and need) is a copy of the list of menu items. If I replace EhCache with Redis, I always get copies (which makes sense, since the redis server is another machine).</p>
  
  <p>So, how can I tell Play to fetch only copies of the cached objects. I really do not want to copy all these objects manually. If there is no build in solution to Play, what would be a generic way?
  Obviously, all objects in the cache are serializable, so I guess one can copy these objects easily.</p>
  
  <p>Thank you,
  schube</p>