Код: Выделить всё
@RestController
class ReportController {
@Autowired
ReportService reportService;
@GetMapping("/getReport")
String getReport(@RequestParam String name) {
Report report = reportService.getReport(name);
return report.toString();
}
< /code>
@Service
class ReportService {
private final ReportHttpInterface reportHttpInterface;
private final ReportLocalDecryptService reportLocalDecryptService;
ReportService(ReportHttpInterface reportHttpInterface, ReportLocalDecryptService reportLocalDecryptService) {
this.reportHttpInterface = reportHttpInterface;
this.reportLocalDecryptService = reportLocalDecryptService;
}
Report getReport(String name) {
String encryptedReport = reportHttpInterface.getReport(name);
String decryptedReport = reportLocalDecryptService.decryptWithLocalKey(encryptedReport);
return new Report(decryptedReport);
}
< /code>
@HttpExchange(accept = MediaType.APPLICATION_JSON_VALUE)
interface ReportHttpInterface {
@Cacheable("report") //FLAG HERE!!!!!!!!!!!!!!!!!!!
@GetExchange("/api/veryexpensivecall/report")
String getReport(@RequestParam String name);
}
< /code>
@Configuration
@EnableCaching
class ReportCacheConfiguration {
@Bean
CacheManagerCustomizer cacheManagerCustomizer(MeterRegistry registry) {
return cacheManager -> cacheManager.registerCustomCache("report", reportCache(registry));
}
private Cache reportCache(MeterRegistry meterRegistry) {
return Caffeine.newBuilder()
.expireAfterWrite(1, TimeUnit.MINUTES)
.recordStats(() -> new CaffeineStatsCounter(meterRegistry, "report"))
.build()
;
}
< /code>
The http request to the external service here is very expensive, hence, I wish to cache this.
This is why you can see the cache configuration, as well as the @Cacheable("report")Проблема: < /p>
< P> Меня помечают на линии @Cachable ("report") с
Spring doesn't recommend to annotate interface methods with @Cache* annotation
< /code>
First of all, after some tests, "it seems to work fine". Meaning, the caching is working.
After the first expensive call, the subsequent calls are very fast, and the third party also confirmed there are no subsequent http requests. For instance, if I call this three times, the first time, it takes long, and the third party app can see my request. But for the second and third calls, it is fast, and the third party service confirmed they did not see anything.
If it is functionally correct, then what is this warning about?
How can I fix it?
Is there some functionality that is actually not working, but I missed?
Подробнее здесь: https://stackoverflow.com/questions/793 ... notation-o
Мобильная версия