Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Default configuration in ehcache.xml is not used on created JCache instances #30

Closed
dzlab opened this issue Oct 31, 2014 · 3 comments
Closed

Comments

@dzlab
Copy link

dzlab commented Oct 31, 2014

I have the following default configuration that I want to be applied to all caches created by CacheManager.createCache(). Here is my ehcache.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect"  dynamicConfig="true"> 
  <!-- see http://www.ehcache.org/ehcache.xml -->
  <defaultCache 
    maxEntriesLocalHeap="200000" 
    eternal="false"
    timeToIdleSeconds="1200"
    timeToLiveSeconds="1200">    
    <persistence strategy="localTempSwap"/>
  </defaultCache>
</ehcache>

I try to create the cache as follows:

String providerName = "org.ehcache.jcache.JCacheCachingProvider";
CachingProvider cachingProvider = Caching.getCachingProvider(providerName);
CacheManager cacheManager = cachingProvider.getCacheManager();
CompleteConfiguration<ComposedKey, Object> config = new MutableConfiguration<ComposedKey, Object>()
    .setTypes(ComposedKey.class, Object.class)
    .setExpiryPolicyFactory(FactoryBuilder.factoryOf(new AccessedExpiryPolicy(new Duration(TimeUnit.MINUTES, 30))))
    .setReadThrough(false)
    .setWriteThrough(false)
    .addCacheEntryListenerConfiguration(
        new MutableCacheEntryListenerConfiguration<ComposedKey, Object>(new CacheListenerManagerJSR107Factory(), null, true,
            true));
;
Cache<ComposedKey, Object> cache = cacheManager.createCache("cache", config);

But it seems the default cache configuration is not used as when debugging the cache has the following attributes:

[ name = orACJ2rF-1 status = STATUS_ALIVE eternal = false overflowToDisk = false maxEntriesLocalHeap = 1000 maxEntriesLocalDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 0 timeToIdleSeconds = 0 persistence = none diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: org.ehcache.jcache.JCacheListenerAdapter ; orderedCacheEventListeners:  maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ]

Also, When I declare a named cache in ehcache.xml and give the same name to CacheManager.createCache() I get a javax.cache.CacheException at org.ehcache.jcache.JCacheManager.createCache(JCacheManager.java:106)

@alexsnaps
Copy link
Member

On the first point, while I think that's the way it should be, I guess it could make some sense as a feature request. But let me ask what you would have expected there? I'm thinking that capacity should be read from the defaultCache config basically. Mainly due to the lack of support for configuration that through the JSR107 API. Anything else you had in mind?

On the second point, not sure what you see as a problem there. The behavior you see is the one spec'ed:

   * If a {@link Cache} with the specified name is known to the {@link
   * CacheManager}, a CacheException is thrown.

Now, what might be unclear, is that when you source your CacheManager from a an ehcache.xml, all Cache instances declared in there will be created for you automatically...

@dzlab
Copy link
Author

dzlab commented Nov 1, 2014

For the first point, I'm expecting the capacity to be read from defaultCache when it's provided in the ehcache.xml because otherwise how I could create new cache instances with a default configuration that I can control.
For the second point, I agree, in fact I tried to create a cache with a name already in ehcache.xml to check if this xml file is really used. But it also makes me wondering why the created caches (i.e. with names not declared in the xml file) are not using the default configuration.

@alexsnaps
Copy link
Member

With regards to your "feature request" in using defaultCache to seed capacity of programmatically created javax.cache.Cache instances, I've created issue #32.
The other points I clear, and stem from confusing naming in Ehcache... And JSR107 lack of "CacheManager.addCache(String)", i.e. w/o explicit Configuration

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants