-1

I have two methods as below .One is annotated with @CachePut and another is annotated with @Cacheable.Both of them uses the same key . Based on some of the answers from other posts I figured that @cacheput replaces the value. If that is the case , would the method annotated with @Cacheable be executed for the same id if there is an update to one of the fields in document.

@CachePut(value="testcache",key="#document.id")
public Document update(Document document){
// code to update db
return document
}

@Cacheable(value="testcache")
public Document getDocument(String id){
// query database and fetch document
 return document
}
rookie
  • 386
  • 6
  • 19

1 Answers1

0

The method annotated with @Cacheable will only be executed if the key has no value in the cache. So, it does not matter whether your @CachePut has updated the document or not. As long as the document is in the cache, getDocument(id) would not go to database. (CachePut does the db & cache update for you)

MMJ
  • 768
  • 5
  • 7