Весна не рекомендует аннотировать методы интерфейса с помощью @cache* Annotation на Spring httpinterfaceJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Весна не рекомендует аннотировать методы интерфейса с помощью @cache* Annotation на Spring httpinterface

Сообщение Anonymous »

У меня есть этот простой кусок кода, в котором я хотел бы кэшировать очень дорогой http -звонок. < /p>

Код: Выделить всё

@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")
в классе httpinterface. Обратите внимание, здесь я использую новую конструкцию httpinterface, не используя свой собственный код, чтобы сделать запрос с шаблоном отдыха или отдыха. < /P>
Проблема: < /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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»