How to set the persistence directory to java.io.tmpdir ?

3,289 views
Skip to first unread message

Niall Cunningham

unread,
Aug 19, 2016, 5:55:37 AM8/19/16
to ehcache-users
  1. What version of Ehcache you are currently using;
  2. Paste the configuration for the Cache/CacheManager you have an issue with;
  3. Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate);
  4. Providing JDK and OS versions maybe useful as well.

1. Ehcache 3.1
2. Xml configuration -> <persistence directory="java.io.tmpdir"/>
3. Spring, javax cache
4. JDK 7, Ubuntu 14

In Ehcache 2.x you could set the disk directory using <diskStore path="java.io.tmpdir"/> to the temp directory. How can this be done with Ehcache 3.x via xml ? The persistence xml element only allows a directory to be used.

Does this need to be done via Java configuration definition ? On the Ehcache getting started page it suggests using a CacheManagerBuilder to set the persistence directory but as i am creating a javax.cache.CacheManager  I have not found a way to set this value.
CacheManagerBuilder.newCacheManagerBuilder()
    .with(CacheManagerBuilder.persistence(getStoragePath() + File.separator + "myData")

Currently I am using a bit of the spring boot code to initialize Ehcache, see below:

    String providerName = "org.ehcache.jsr107.EhcacheCachingProvider";
    CachingProvider cachingProvider = Caching.getCachingProvider(providerName);

    Resource configLocation =  context.getResource("classpath:ehcache.xml");
    javax.cache.CacheManager cacheManager  = cachingProvider.getCacheManager(configLocation.getURI(),
                    cachingProvider.getDefaultClassLoader(),
                    createCacheManagerProperties(configLocation))


    private Properties createCacheManagerProperties(Resource configLocation)
            throws IOException {
        Properties properties = new Properties();
        properties.setProperty("hazelcast.config.location", configLocation.getURI()
                .toString());
        return properties;
    }


Can this be set by property on the javax.cache.CacheManager or by another way ?

Thanks in adance,

Niall






Chris Dennis

unread,
Aug 22, 2016, 11:08:36 AM8/22/16
to ehcach...@googlegroups.com
Currently there is no property substitution mechanism in the Ehcache 3 configuration format. I think this is a good candidate for filing as an issue in github. If you do that then we can have some discussion there about whether/how best to achieve this.

Thanks,

Chris
> On Aug 19, 2016, at 5:55 AM, Niall Cunningham <niall.cu...@gmail.com> wrote:
>
> • What version of Ehcache you are currently using;
> --
> You received this message because you are subscribed to the Google Groups "ehcache-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
> To post to this group, send email to ehcach...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/f21787e6-a3bc-48d8-87ec-df72f34e114d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Louis Jacomet

unread,
Oct 18, 2016, 4:31:06 AM10/18/16
to ehcach...@googlegroups.com
Hi Niall,

FYI property substitution was added to Ehcache as of version 3.1.3.

In short you can use "${sys.prop}" values wherever this is allowed by the XSD and it will be replaced by the matching system property.
Note that in case the system property is not found, this will cause an exception to be thrown.

Regards,
Louis

ma...@bwaldvogel.de

unread,
Oct 18, 2016, 4:47:45 AM10/18/16
to ehcache-users
Hi Niall, Chris and Louis

I've created an issue on GitHub: https://github.com/ehcache/ehcache3/issues/1545

Note that system property substitution wouldn't suffice in my use-case since I would want to use a value from a properties file.

Regards,
Benedikt

Reply all
Reply to author
Forward
0 new messages