我正在尝试创建一个以对为键的缓存,并从帖子。
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:
CacheBuilder类型的build(CacheLoader)方法不适用于自变量(新的 CacheLoader,String>(){})
The method build(CacheLoader) in the type CacheBuilder is not applicable for the arguments (new CacheLoader,String>(){})
有人对如何解决这个问题有任何建议吗?我需要有一个缓存来存储主键为评级代理 +评级的 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缓存
发布评论