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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With