How to get the configuration of a given cache in Apache Ignite?
<p>For instance, I configure the cache the following way:</p>

<pre class="lang-java prettyprint-override"><code>public IgniteCache&lt;String, Object&gt; getOrCreateCache(String cacheName) {
    Ignite ignite = Ignition.ignite();

    CacheConfiguration&lt;String, Object&gt; cacheCfg = new CacheConfiguration&lt;String, Object&gt;(cacheName);
    cacheCfg.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 30)));

    IgniteCache&lt;String, Object&gt; igniteCache = ignite.getOrCreateCache(cacheCfg);
    return igniteCache;     
}
</code></pre>

<p>Now what if later I would like to find out the duration of the expiry policy from the returned igniteCache. I can do it in the following hacky way, but it is ugly and can not be the right way:</p>

<pre class="lang-java prettyprint-override"><code>import javax.cache.configuration.Factory;
import javax.cache.expiry.CreatedExpiryPolicy;
import javax.cache.expiry.Duration;

import org.apache.ignite.IgniteCache;
import org.apache.ignite.configuration.CacheConfiguration;

public class IgniteCacheManager {

    private IgniteCache&lt;String, Object&gt; igniteCache;

    public IgniteCacheManager(IgniteCache&lt;String, Object&gt; igniteCache) {
        this.igniteCache = igniteCache;
    }

    public long getTimeToLive() {
        long timeToLive = 0;
        CacheConfiguration configuration = igniteCache.getConfiguration(CacheConfiguration.class);
        Factory factory = configuration.getExpiryPolicyFactory();
        Object obj = factory.create();
        if (obj instanceof CreatedExpiryPolicy) {
            CreatedExpiryPolicy cep = (CreatedExpiryPolicy)obj;
            Duration dur = cep.getExpiryForCreation();
            timeToLive = dur.getDurationAmount();
        }
        return timeToLive;
    }
}
</code></pre>

<p>The Apache Ignite version I'm working on is 1.5.0.final</p>

<p>By the way, in Ehcache, I can simply get the configuration the following way:</p>

<pre class="lang-java prettyprint-override"><code>import net.sf.ehcache.Cache;
import net.sf.ehcache.config.CacheConfiguration;

public class EhcacheCacheManager {

    private Cache cache;

    public EhcacheCacheManager(Cache cache) {
        this.cache = cache;
    }

    public long getTimeToLive() {
        long timeToLive = 0;

        CacheConfiguration config = cache.getCacheConfiguration();
        timeToLive = config.getTimeToLiveSeconds();
        return timeToLive;
    }
}
</code></pre>