Senior
Question 7. Il y a un service ExampleService (voir l'image). Si un service externe appelle en séquence: exampleService.getCityFromCache(100000); exampleService.getCity(100000); Combien de fois l'appel à CityDao::getCity sera-t-il effectué si le cache était vide? @Component @RequiredArgsConstructor public class ExampleService { private final CityDao dao; @Cacheable public String getCityFromCache(int index) { return dao.getCity(index); } public String getCity(int index) { return getCityFromCache(index); } } 0 1 2 Cela dépend de l'implémentation de CacheManager
sobes.tech IA
Réponse de l'IA
Обращение к CityDao::getCity будет выполнено один раз.
Пояснение:
- Метод
getCityFromCacheпомечен аннотацией@Cacheable, значит при первом вызове с параметром100000результат будет получен изdao.getCity(100000)и закэширован. - Второй вызов
exampleService.getCity(100000)вызывает внутри себяgetCityFromCache(100000), но так как результат уже в кэше,dao.getCityне вызывается повторно.
Итог: при пустом кэше первый вызов вызывает DAO, второй — использует кэш.
Ответ: 1.