Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Spring @Cache* on Feign client?

I have a Feign client that requests a token from a microservice. Since I am making multiple calls, I would like to cache the responses received from the Feign client and use Spring Guava caching, but it doesn't seem to work. All I have is the configuration class and the annotation on the Feign client.

I read somewhere on stack overflow that Feign might not support @Cacheable annotation. Is this true?

like image 902
Bianca Avatar asked Apr 03 '18 11:04

Bianca


People also ask

Which is better feign or RestTemplate?

One of the advantages of using Feign over RestTemplate is that, we do not need to write any implementation to call the other services. So there is no need to write any unit test as there is no code to test in the first place.

Is feign client deprecated?

Feign client is really convenient tool to use. But I recently came to know that Rest-Template is going to be deprecated and will be replaced by WebClient, and Feign Client internally uses Rest-Template.

What is the use of Feign client in spring boot?

Feign is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it. It has pluggable annotation support including Feign annotations and JAX-RS annotations.


1 Answers

Finally, I managed to solve my issue. What I did in the end is :

-> Create new @Service annotated class

-> Inject interface with @FeignClient annotation

-> Put all @Cache related annotations ( using @Caching annotation) on the method that calls methods from the interface.

It works! :)

like image 117
Bianca Avatar answered Sep 22 '22 11:09

Bianca