7

I'm trying to create a Cache that has a "Pair" as its key, with that Pair class taken from this post.

I'm trying:

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);

Which fails to compile in Eclipse (helios, java 1.6) with:

The method build(CacheLoader) in the type CacheBuilder is not applicable for the arguments (new CacheLoader,String>(){})

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".

Guava 10.0.1

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Maarten Boekhold
  • 867
  • 11
  • 21
  • 1
    Hmmm, embarrassed.... My first question on StackOverFlow, and already I mess up. 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. Seems to be working now, or at least it compiles. – Maarten Boekhold Nov 01 '11 at 10:33
  • Don't feel embarrassed. It happens to me all the time. I guess you used SO as your rubber duck: http://en.wikipedia.org/wiki/Rubber_duck_debugging ;) – Etienne Neveu Nov 01 '11 at 14:11
  • So is there anything left that needs to be answered? Or can the question be withdrawn? – daveslab Nov 01 '11 at 18:48
  • Hi, no, no question to be answered anymore. Because I am a new StackOverflow user I couldn't post the answer myself immediately. Will do so now. – Maarten Boekhold Nov 02 '11 at 05:36

1 Answers1

8

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.

So a simple change from:

Cache<String, String> _ratingAgencyId;

to

Cache<Pair<String, String>, String> _ratingAgencyId;

did the trick.

Maarten Boekhold
  • 867
  • 11
  • 21