1

I've seen lots of examples of using things like Netflix's @HystrixCommand on service methods, but is it possible to enable a circuit breaker when using one or more CacheManager instances? In other words, bypass the Spring cache if the underlying service is unavailable or unstable over time.

Specifically, in our usage of Spring Cache, we simply have a method annotated with @Cacheable. Typically with a circuit breaker you specify a fallback, but our fallback is "Dont' use the cache, just execute our method normally". How would we implement that with annotations? Do we need to refactor our code to separate the CacheManager calls?

GabeV
  • 859
  • 8
  • 21

1 Answers1

0

I think you should write a custom cache manager and write the circuit breaker logic there.

@Component
public  CacheManager CustomCacheManager implements CacheManager  {

    @Override
    public Cache getCache(String s) {
        return null;
    }

    @Override
    public Collection<String> getCacheNames() {
        return null;
    }
}
Mandar Pandit
  • 2,171
  • 5
  • 36
  • 58
Srini M
  • 196
  • 3
  • 16