0

In ehcache2, I stored my properties externally and read them using a input stream which was an available option for configuring this, but the same option isn't present in ehcache3. ehcache2 code which works: https://www.ehcache.org/documentation/2.8/code-samples.html

Create a CacheManager from a configuration in an InputStream.

try {
  CacheManager manager = CacheManager.newInstance(fis);
} finally {
  fis.close();```

Is there any work around for the same in ehcache3?
Soccergods
  • 440
  • 5
  • 17

1 Answers1

0

Ehcache3 doesn't have as straightforward a way of doing this as was present in ehcache2, but it definitely is possible.

You need to use the "import org.w3c.dom.Document" class and pass a Document to the XMLConfiguration constructor which you can use to build your cache manager:

cacheManager = CacheManagerBuilder.newCacheManager(xmlConfiguration);

The document itself is build like this:

      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      Document document = factory.newDocumentBuilder().parse(inputStream);
      XMLConfiguration xmlConfiguration = new XMLConfiguration(document);

And now it should work. You might have xml related errors, but otherwise, this should work perfectly normal if your xml is of the correct format.

Soccergods
  • 440
  • 5
  • 17