3

I'm trying to create a simple (non-loading) cache with Caffeine.

Cache<String, MyObject> countsCache =   
    CacheBuilder.newBuilder().build();

This fails to compile, with the Error reported:

Error:(42, 31) java: incompatible types: 
no instance(s) of type variable(s) K1,V1 exist so that org.elasticsearch.common.cache.Cache<K1,V1> conforms to com.github.benmanes.caffeine.cache.Cache<java.lang.String,com.foo.bar.MyObject>

Any suggestions would be greatly appreciated.

L. Blanc
  • 2,150
  • 2
  • 21
  • 31

1 Answers1

10

It appears that you imported the ElasticSearch's Cache interface to assign to the result of the cache builder. The builder syntax you showed is Guava's CacheBuilder. Because many users would have Guava and might migrate, the builder is called Caffeine to reduce confusion.

You should be able to construct a cache like,

Cache<String, MyObject> countsCache = Caffeine.newBuilder().build();
Ben Manes
  • 9,178
  • 3
  • 35
  • 39