title: @Cacheable and @CachePut different return type
body: <p>(<a href="https://stackoverflow.com/questions/17946426/will-springs-cacheput-annotation-work-with-a-void-return-type">Will Spring&#39;s @CachePut annotation work with a void return type?</a>)</p>
  
  <p>I encountered the same problem</p>
  
  <p>Because the problem has been for a long time, I do n’t know if there is a solution</p>
  
  <p>created a cache:</p>
  
  <pre><code>public static final String Key = "CacheKey";
  
  @Cacheable(cacheNames = "userCache", key = "Key")
  public List&lt;User&gt; getAllUsers() {
  ...
  }
  </code></pre>
  
  <p>update this cache using the @CachePut</p>
  
  <pre><code>@CachePut(cacheNames = "userCache", key = "Key")
  public User addUser(User user) {
  ...
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>com.example.demo.dto.UserDTO cannot be cast to java.util.List
  </code></pre>
  
  <p>I searched for information for several days, but did not find the answer</p>
  
  <p>In addition to using @CacheEvict (cacheNames = userCache, allEntries = true)</p>
  
  <p>Is there a way to solve it using @Cacheable and @CachePut?</p>
  
  <p>Thank you</p>