问题描述
我正在尝试创建一个以对为键的缓存,并从帖子。
I'm trying to create a Cache that has a "Pair" as its key, with that Pair class taken from this post.
我正在尝试:
CacheLoader<Pair<String, String>, String> loader =
new CacheLoader<Pair<String, String>, String>() {
public String load(Pair<String, String> key) {
return GetRatingIdentityByShortNameLoader(key.first, key.second);
}
};
_ratingIdCache = CacheBuilder.newBuilder()
.concurrencyLevel(a_conclevel.intValue())
.maximumSize(a_maxsize.intValue())
.expireAfterAccess(a_maxage.intValue(), TimeUnit.MINUTES)
.build(loader);
在Eclipse(Helios,Java 1.6)中无法通过以下方式进行编译:
Which fails to compile in Eclipse (helios, java 1.6) with:
有人对如何解决这个问题有任何建议吗?我需要有一个缓存来存储主键为评级代理 +评级的 ID的目标。
Does anybody have any suggestions on how to solve this? The objective that that I need to have a cache that stores an "ID" for which the "primary key" is "Rating Agency" + "Rating".
番石榴10.0 .1
Guava 10.0.1
推荐答案
我最初将此高速缓存定义为Cache,并且当我更改CacheBuilder.build()以使用复杂的密钥,我忘了更新缓存声明。
I had this cache originally defined as Cache, and when I change the CacheBuilder.build() to use a complex key, I had forgotten to update my cache declaration.
所以从以下简单更改:
Cache<String, String> _ratingAgencyId;
到
Cache<Pair<String, String>, String> _ratingAgencyId;
有帮助。
这篇关于使用复杂密钥创建Google Guava缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!