Hi guys,
I want to migrate my application using Ehcache from 2.10 to latest version, so 3.5.2. I've looked over the migration guide here :
http://www.ehcache.org/documentation/3.5/migration-guide.html but it has not been helpful at all.
I've looked around the forum and I did not find any similar topics so I'm going to ask all my questions here. Hopefully, I'll be able to gather some answers and improve the migration guide so that it will be easier for future users.
Basically, I had an
ehcache.xml describing several cache associated to several names, for example :
<cache name="template_message"
maxEntriesLocalHeap="100"
statistics="false"
eternal="false"
maxEntriesLocalDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LFU">
<persistence strategy="localTempSwap"/>
</cache>
<cache name="template_thread"
maxEntriesLocalHeap="1000"
statistics="false"
eternal="false"
maxEntriesLocalDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LFU">
<persistence strategy="localTempSwap"/>
</cache>
Then I was able to retrieve that file into a
Configuration object, and to pass it to a
CacheManager. It was also possible to configure a
DiskStoreConfiguration along. It looked like that :
try {
Configuration cfg = new Configuration();
URL urlConfig = Loader.getDefault().getResource(DEFAULT_CONFIG);
cfg = ConfigurationFactory.parseConfiguration(stream);
DiskStoreConfiguration dsc = cfg.getDiskStoreConfiguration();
if (dsc == null) {
dsc = new DiskStoreConfiguration();
cfg.addDiskStore(dsc);
}
String path = configureDiskPath(dsc.getPath());
dsc.setPath(path);
manager = CacheManager.create(cfg);
Now, I am trying to do the same but with Ehcache 3. I'm not getting into the xml because I think it would be quite easy. I'm currently struggling with the Configuration. I was able to specify an XML configuration and to configure the diskStore. Is it no possible anymore? Or is everything configured in the XML?
What I do now is that :
CacheManagerBuilder<CacheManager> builder = CacheManagerBuilder.newCacheManagerBuilder();
CacheManagerConfiguration<PersistentCacheManager> conf = CacheManagerBuilder.persistence(path);
CacheManagerBuilder<PersistentCacheManager> newBuilder = builder.with(conf);
manager = newBuilder.build();
manager.init();
So I'm simply building a
persistent CacheManager. And when I create the Cache, I retrieve the XMLConfiguration and give it to that manager :
CacheConfiguration cConf = CacheWrapperManager.getInstance().getXmlConfiguration().getCacheConfigurations().get(cacheTemplateName);
cache = manager.createCache(cacheName, cConf);
In theory, I should have a
Cache that follow the configuration given in the XML, and is persistent on disk right?
But really I'm diving into darkness here and I'm not sure at all about what I'm doing. For example, when I create the Cache, I give a
cacheName.
Now I want to remove that Cache, so I want to call the
remove method of the
CacheManager, but it needs the alias. This alias is nowhere to be seen in the
Cache interface?! And the CacheManager has no
remove methods taking a Cache object directly.
Last but not least, I used to check the Cache Status before. This Status is nowhere to be seen now, and the only Status I see is on the CacheManager itself. Is there a way to check the status of a specific cache?
Any help, links, answers are really appreciated,
Regards,
Hadzic Samir