I want to have a cache that holds a list of items. This is my bean definition:
public Cache<Integer, List<Application>> getMyCacheManager(CacheManager manager) {
Cache<Integer, List<Application>> cache = manager.getCache("myCache");
if (Objects.isNull(cache)) {
var config = new MutableConfiguration<Integer, List<Application>>()
.setTypes(Integer.class, List.class)
.setStoreByValue(false)
.setStatisticsEnabled(true)
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, myCacheExpiry)));
cache = manager.createCache("myCache", config);
}
return cache;
}
The problem is the .setTypes
line. Here you have to specify the key and value types of the cache. The key is straight forward, but the value is a List<Application>
type. You can't just say: List<Application>.class
, because that is not allowed. And you also can't use List.class
, because the compiler complaints the types are not compatible.
I would really like to keep the specific type (eg List<Application>
) because else I have to cast the value every time from Object
to the right type.
Any ideas?