1

我有一个带有 Hystrix(Javanica)和 JCache(EHCache 实现)的 SpringBoot(2.1.7)应用程序。我@HystrixCommand有用注释注释的方法来为它们启用 Hystrix。我也对这些方法进行了缓存。它看起来像这样:

@Override
@HystrixCommand(fallbackMethod = "fallbackGetAllUserProfiles")
@Timed(histogram = true, percentiles = {0.75, 0.9, 0.95, 0.99})
@CacheResult
public UserProfiles getAllUserProfiles(@CacheKey String accountID, @CacheKey String userID) {
    return getAllUserProfilesFromBackend(accountID, userID);
}

UserProfiles getAllUserProfilesFromBackend(String accountID, String userID) {
   // call to backend; omitted for readability
}}

现在我正在查看文档,实际上有 2 个不同的@CacheResult注释:一个来自 JCache (jsr-107),一个来自 Javanica (Hystrix)。

如果我还希望 Hystrix 使用缓存,我是否也应该指定第二个@com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult

或者我可以更好地移动@CacheResult到方法getAllUserProfilesFromBackend,然后用 Hystrix 注释 Hystrix 方法@CacheResult吗?

我只是想知道,因为 Hystrix 框架可以在服务失败的情况下使用缓存,但我不清楚它是否自动使用 JCache。

4

0 回答 0