1
votes

We are moving away from HttpClient to now use RestTemplate, even better FeignClient. But looking at the https://github.com/OpenFeign/feign it seems Response Caching is in road map of feign 11.

I was looking at possibility of writing a custom mechanism to support Caching based on Cache Control headers. I will try to explain this with sample example

Service A exposes an API /greet/{name}. This API sends max-age response header so that client can cache the response.

Service B calls this API using FeignClient

Below is sample Feign Interface.

@FeignClient(name="app/app", contextId="AppService", configuration=AppConfig.class)
public interface AppFeignService {

    @GET
    @Path(value = "/api/greet/{name}")
    public String greet(@PathParam("name") String name);
}

One way to support caching is, add an intermediate layer above feign client and cache the response based on needs. But this takes the caching logic to client side and I want to make sure the decision of how much to cache (max-age header) should be left to server and client shouldn't drive it.

Question here is - do we know when we can expect caching support in Feign? Is there any interim solution we can go with to still have caching support? Feign is really good considering its abstraction and we do not really want to write code to call it using RestTemplate.

Your recommendations are highly appreciated.

1

1 Answers

0
votes

I am actually building my own hobby app and was thinking about exactly same thing and then I hit upon your question. What I have decided so far is to use a okhttpClient as proxy (this one has a very good caching support) to my micro-service. I am using spring boot. I am looking for a way to do it. So every request from the Fiegn client will first hit my okhttp client with caching support and then it will do all the magic, to forward the request to eureka server micro service or not. My micro service uses a very specific http client to do the request and I don;t want to touch that part.