When you use the @Cacheable annotation, the code that implements the cache search is outside your method. Therefore, a synchronized modifier does not affect it.
If you want all streams to use the caching result, you must create a synchronized method that transfers the call to the getNextPlaying caching method. Something like that:
public synchronized List<Match> getNextPlayingSynchronized(Date startingFrom, Locale locale){ return getNextPlaying(Date startingFrom, Locale locale); } ... @Cacheable(value="nextPlaying", key = "#startingFrom.getYear() + #startingFrom.getMonth() + #startingFrom.getDay() + #startingFrom.getHours() + #startingFrom.getMinutes() + #locale.getLanguage()") public List<Match> getNextPlaying(Date startingFrom, Locale locale){ ...
It is important that these methods are in different classes. Otherwise, the aspects do not work.
source share