使用复杂密钥创建Google Guava缓存

编程入门 行业动态 更新时间:2024-10-26 04:28:55
本文介绍了使用复杂密钥创建Google Guava缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个以对为键的缓存,并从帖子。

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缓存

本文发布于:2023-10-30 03:28:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541627.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密钥   缓存   Google   Guava

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!