title: Spring boot @CachePut, how it works
body: <p>I'm trying to update values in spring cache, however @CachePut does not replace actual value, but put another value with the same key:</p>
  
  <p>Cachename: noTimeCache:</p>
  
  <ul>
  <li>Key: SYSTEM_STATUS, val: ON</li>
  <li>Key: SYSTEM_STATUS, val: OFF</li>
  </ul>
  
  <p>1.Why?</p>
  
  <p>My cache service:</p>
  
  <pre><code>@CachePut(value = "noTimeCache", key = "#setting.getSetting().name()")
  public String updateGlobalCacheValue(GlobalSettings setting) {
      System.out.println("Setting: " + setting.getSetting().name() + ", val: " + setting.getValue());
      return setting.getValue();
  }
  </code></pre>
  
  <p>I know it's looks funny but i need to work with jpa repositories. Maybe someone have better solution.</p>
  
  <p>2.Why can't I use function argument as @Cacheable key like this?</p>
  
  <pre><code>@Cacheable(value = "noTimeCache", key = "#setting.name()", unless = "#result == null")
  @Query("SELECT gs.value FROM GlobalSettings gs WHERE gs.setting = ?1")
  String getGlobalSettingValue(Settings setting);
  </code></pre>
  
  <p>It tells me setting is null.</p>
  
  <p>3.Is the way to override @Repositository interface methods, for example save() to add annotation @Cacheable to them?</p>