title: Using Cache in Play Framework
body: <p>I'm trying to implement a quiz application. The application loads the questions with ajax one by one. When a user clicks the 'to next question' button his/her answer is saved in cache. But when I debug, cache list is always null...</p>
  
  <p>This code creates the first cache array:</p>
  
  <pre class="lang-java prettyprint-override"><code>public static void viewQuiz(@Required String user, @Required String test) {        
          if(validation.hasErrors()) {
              flash.error("Hoop kullanıcı lazım…");
              index();
          } else{
              TestClass selectedTest = TestClass.find("title", test).first();
              List&lt;String&gt; choiceList = new ArrayList&lt;String&gt;();
              session.put("testID", selectedTest.id);
              Cache.set("choices", choiceList, "30mn");
              render();
          }
      }
  </code></pre>
  
  <p>And this code is trying to save the answers one by one:</p>
  
  <pre class="lang-java prettyprint-override"><code>public static void question(@Required Long id, String answer){
      Long testId = Long.parseLong(session.get("testID"));
      TestClass test = TestClass.findById(testId);
      List&lt;Question&gt; questList = Question.find("test_id", test.id.intValue()).fetch(); 
      Question quest = questList.get(id.intValue());
      if(answer != null){
          List&lt;String&gt; choiceList= Cache.get("choices",List.class);
          choiceList.add(id.intValue(), answer);
          Cache.set("choices", choiceList, "30mn");
      }   
      int count = questList.size()-1; 
      render(quest, count, id);
  }
  </code></pre>
  
  <p>And this code is the html view of the second:</p>
  
  <pre class="lang-xhtml prettyprint-override"><code> #{extends 'main.html' /}
  
  #{set title:'question.html' /}
  
  &lt;script type="text/javascript"&gt; 
          var questionId = ${id};
          $('#nextButton').click(function(){
          $('#questionDiv').html('&lt;p&gt;&lt;img id = "loaderGif" src="public/images/loading.gif"/&gt;&lt;/p&gt;');
  
          $('#questionDiv').load("/test/" + ++questionId);
  
      });
      $('#endButton').click(function(){
          $('#questionDiv').html('&lt;p&gt;&lt;img id = "loaderGif" src="public/images/loading.gif"/&gt;&lt;/p&gt;');
          $('#questionDiv').load("/result");
      });
   &lt;/script&gt; 
  
  &lt;legend&gt;Soru ${id+1}&lt;/legend&gt;
  &lt;p&gt;&amp;{quest.question}&lt;/p&gt;
  
  #{list items:quest.choices, as:'choice'} 
  &lt;p&gt;&lt;input type="radio" name = "answer" id = "answer" size="30" value="${choice}"/&gt;&amp;{choice}&lt;/p&gt;
  #{/list}
  #{if id &lt; count}
  &lt;input id = "nextButton" name="nextButton" type="button" value="İleri"/&gt;
  #{/if}
  #{else}
  &lt;input id = "endButton" name="endButton" type="button" value="Bitti"/&gt;
  #{/else}
  </code></pre>