I need to initialize the Cache which needs to contain
String in key
List<Object> in value
So i have CacheHelper class which has
public class CacheHelper {
private CacheManager cacheManager;
private Cache<String,List<Person>> cacheDataList;
private static final String CACHE_PERSON="cache_key_person";
public CacheHelper() {
}
public void putInCacheFromDb(){
System.getProperties().setProperty("java -Dnet.sf.ehcache.use.classic.lru", "true");
cacheManager= CacheManagerBuilder
.newCacheManagerBuilder().build();
cacheManager.init();
cacheDataList = cacheManager
.createCache("cacheOfPersonList", CacheConfigurationBuilder
.newCacheConfigurationBuilder(
String.class,Person.class,
ResourcePoolsBuilder.heap(10)).withExpiry(Expirations.timeToLiveExpiration(Duration.of(60,
TimeUnit.SECONDS))));
}
public void putInList(List<Person> personList){
System.out.println("putting list in cache");
cacheDataList.put(CACHE_PERSON,personList);
}
}
But at this line of code,I am not able to conver object into list String.class,Person.class ,which needs to be String.class,List:
cacheDataList = cacheManager
.createCache("cacheOfPersonList", CacheConfigurationBuilder
.newCacheConfigurationBuilder(
String.class,Person.class,
ResourcePoolsBuilder.heap(10)).withExpiry(Expirations.timeToLiveExpiration(Duration.of(60,
TimeUnit.SECONDS))));
But I am getting error as:
Incompatible types. Required Cache<String, List<Person>> but 'createCache' was inferred to Cache<K, V>: Incompatible equality constraint: List<Person> and Person
I need to store List in a single key.how can I initialize it?