【问题标题】:How do you use Spring Circuit Breaker with Cache Manager?您如何将 Spring Circuit Breaker 与缓存管理器一起使用?
【发布时间】:2020-03-04 06:36:20
【问题描述】:

我已经看到很多在服务方法上使用 Netflix 的 @HystrixCommand 之类的示例,但是在使用一个或多个 CacheManager 实例时是否可以启用断路器?换句话说,如果随着时间的推移底层服务不可用或不稳定,则绕过 Spring 缓存。

具体来说,在我们使用 Spring Cache 时,我们只是有一个用@Cacheable 注释的方法。通常使用断路器,您指定回退,但我们的回退是“不要'使用缓存,只需正常执行我们的方法”。我们将如何使用注释来实现它?我们是否需要重构我们的代码来分离CacheManager 调用?

【问题讨论】:

    标签: spring spring-data-redis spring-cache circuit-breaker redis-cache


    【解决方案1】:

    我认为你应该编写一个自定义缓存管理器并在那里编写断路器逻辑。

    @组件 public CacheManager CustomCacheManager 实现 CacheManager {

    @Override
    public Cache getCache(String s) {
        return null;
    }
    
    @Override
    public Collection<String> getCacheNames() {
        return null;
    }
    

    }

    【讨论】:

      猜你喜欢
      • 2020-09-24
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 2021-01-11
      • 2016-04-02
      • 2016-05-05
      • 2018-02-10
      相关资源
      最近更新 更多