Feign: How to enable @CacheResult in feign client

Created on 22 Apr 2018  ·  3Comments  ·  Source: OpenFeign/feign

invalid

Most helpful comment

@CacheResult is a Spring concept, part of their Cache Abstraction. Feign does not have first class support for these constructs, but you can use them in concert.

First, adding these annotations to Interfaces is not recommended. See Enable caching annotations in the Spring Documentation

It is recommended that you add the annotations to a concrete class. For example:

public class UserRepository {
   // our feign client
   private GitHub gitHub;

  // find the github user and cache the result
  @CacheResult
  public User findByName(String name) {
      return this.gitHub.findUser(name);
  }
}

In this example, Feign is responsible for calling the API and the UserRespository is responsible for caching the results. Hope this helps.

All 3 comments

What is @CacheResult?

@CacheResult is a Spring concept, part of their Cache Abstraction. Feign does not have first class support for these constructs, but you can use them in concert.

First, adding these annotations to Interfaces is not recommended. See Enable caching annotations in the Spring Documentation

It is recommended that you add the annotations to a concrete class. For example:

public class UserRepository {
   // our feign client
   private GitHub gitHub;

  // find the github user and cache the result
  @CacheResult
  public User findByName(String name) {
      return this.gitHub.findUser(name);
  }
}

In this example, Feign is responsible for calling the API and the UserRespository is responsible for caching the results. Hope this helps.

This is a question regarding Spring Cache Abstraction usage and not Feign.

Was this page helpful?
0 / 5 - 0 ratings