我将尝试解释 Hystrix 请求缓存 是如何工作的,但是我并没有理解他们在文档中提供的例子。
事实上,我有以下的 HystrixCommand
子类:
public class GetFizzCommand extends HystrixCommand<Fizz> {
private Long id;
private Map<Long,Fizz> fizzCache = new HashMap<Long,Fizz>();
void doExecute(Long id) {
this.id = id;
execute();
}
@Override
public Fizz run() {
return getFizzSomehow();
}
@Override
public Fizz getFallback() {
// Consult a cache somehow.
// Perhaps something like a Map<Long,Fizz> where the 'id' is the key (?)
// If the 'id' exists in the cache, return it. Otherwise, give up and return
// NULL.
fizzCache.get(id);
}
}
我觉得我在这里可能与大家背道而驰。我相信Hystrix提供了内置缓存,这可以从'cacheKey'看出来,但我找不到任何有效的示例。我不想重复造轮子,如果已经有现成的解决方案了,我就不需要再将缓存构建到我的命令中。
所以我问:Hystrix的请求缓存是什么样子的(确切地说)?如何向缓存添加条目?何时/如何清空缓存?它是否可配置(过期时间、最大大小等)?