title: Caching java method
body: <p>I want to cache heavy method result, but I for some reason it would not store in cache.</p>
  
  <p>I had tried to use spring cache but it only worked when caching whole api where I only need to cache part of it.</p>
  
  <pre><code>@ResponseBody
  public Person validateTest(@Param("name") String name) {
      return cache(name);
  }
  
  @Cacheable(value = "getName", key = "#name")
  public Person cache(String name) {
      Person person = generateString(name);
      return person;
  }
  
  
  public Person generateString(String name) {
      System.out.println("generating");
      Person person = new Person();
      person.setName(name);
      return person;
  }
  
  
  
  @Data
  class Person implements Serializable { 
     private String name;
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/S0Z8c.png" rel="nofollow noreferrer">StackTrace of requests</a></p>
  
  <p><em>@EnableCaching</em> is enabled</p>