OK, maybe it's easier to explain what I'm looking for and you can recommend
the correct JCache way of doing things. I want to use a named cache
initialized by a configuration file. The named cache should be considered a
Singleton, since I should be able to share it between applications and
especially method invocations. I did another commit that moved the
configuration files out of the main and test classpath. This resulted in
the cache not initializing for each test method. For each test using
Ehcache provider I see (using annotations):
WARNING: No Cache named 'testCache' was found in the CacheManager, a
default cache will be created.
I do not want the default cache, I want testCache. Also the @CacheResult
method isn't working correctly since it's adding the came key again:
cacheManager = cachingProvider.getCacheManager(new
File("src/config/ehcache.xml").toURI(), null, null);
Sep 15, 2015 7:14:51 PM com.codeferm.jcache.tomee.KeyValueBean
invalidateCache
INFO: Cache invalidated
Sep 15, 2015 7:14:51 PM com.codeferm.jcache.tomee.KeyValueBean slowMethod
INFO: Adding key: key1, value: value1
Sep 15, 2015 7:14:51 PM com.codeferm.jcache.tomee.KeyValueBean slowMethod
INFO: Adding key: key2, value: value2
Sep 15, 2015 7:14:51 PM com.codeferm.jcache.tomee.KeyValueBean slowMethod
INFO: Adding key: key3, value: value3
Sep 15, 2015 7:14:51 PM com.codeferm.jcache.tomee.KeyValueBean slowMethod
INFO: Adding key: key1, value: value1
but if I do:
cacheManager = cachingProvider.getCacheManager() with ehcache.xml in
src/main/resources
Sep 15, 2015 7:26:00 PM com.codeferm.jcache.tomee.KeyValueBean
invalidateCache
INFO: Cache invalidated
Sep 15, 2015 7:26:00 PM com.codeferm.jcache.tomee.KeyValueBean slowMethod
INFO: Adding key: key1, value: value1
Sep 15, 2015 7:26:00 PM com.codeferm.jcache.tomee.KeyValueBean slowMethod
INFO: Adding key: key2, value: value2
Sep 15, 2015 7:26:00 PM com.codeferm.jcache.tomee.KeyValueBean slowMethod
INFO: Adding key: key3, value: value3
it works. The only way JCache providers seem to work correctly is loading
configuration from default classpath.
On Tue, Sep 15, 2015 at 5:00 PM, Romain Manni-Bucau <[email protected]>
wrote:
> looks like behaving correctly according your config which is initialized by
> the backing JCS cache manager - not the JCache facade one.
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> | Blog
> <http://rmannibucau.wordpress.com> | Github <
> https://github.com/rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com>
>
> 2015-09-15 12:44 GMT-07:00 Steve Goldsmith <[email protected]>:
>
> > It's there https://github.com/sgjava/jcache-tomee. CacheBeanTest has
> been
> > modified not to use testCache =
> > cacheBean.getCacheManager().getCache("testCache"), only annotations. You
> > will see from the logging that the default cache is created several
> times.
> > This makes no sense. I'll switch back to EHcache and see what it does
> while
> > you are looking at the source. UserServiceJCacheTest will fail because it
> > compares cache with cacheBean.getCacheManager().getCache("testCache").
> >
> >
> >
> >
> > On Tue, Sep 15, 2015 at 2:35 PM, Romain Manni-Bucau <
> [email protected]
> > >
> > wrote:
> >
> > > can you push it all to github? maybe some semantic issue in our
> > > communication so would check it on a running example
> > >
> > >
> > > Romain Manni-Bucau
> > > @rmannibucau <https://twitter.com/rmannibucau> | Blog
> > > <http://rmannibucau.wordpress.com> | Github <
> > > https://github.com/rmannibucau> |
> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > <http://www.tomitribe.com>
> > >
> > > 2015-09-15 10:48 GMT-07:00 sgjava <[email protected]>:
> > >
> > > > OK, I tried the snapshot again and it still creates a default cache
> > > trying:
> > > >
> > > > @PostConstruct
> > > > public void init() {
> > > > log.info("PostConstruct");
> > > > cachingProvider = Caching.getCachingProvider();
> > > > //cacheManager = cachingProvider.getCacheManager();
> > > > log.info("getCacheManager");
> > > > cacheManager = cachingProvider.getCacheManager(new File(
> > > > "src/main/resources/jcache.ccf").toURI(),
> > > > Thread.currentThread().getContextClassLoader(),
> > > > cachingProvider.
> > > > getDefaultProperties());
> > > > }
> > > >
> > > > It still creates a default cache after calling getCacheManager:
> > > >
> > > > Sep 15, 2015 1:49:06 PM com.codeferm.jcache.tomee.CacheBean init
> > > > *INFO: PostConstruct*
> > > > Sep 15, 2015 1:49:06 PM com.codeferm.jcache.tomee.CacheBean init
> > > > *INFO: getCacheManager*
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.utils.threadpool.ThreadPoolManager loadConfig
> > > > INFO: thread_pool.default PoolConfiguration = useBoundary = [true]
> > > > boundarySize = [2000] maximumPoolSize = [150] minimumPoolSize = [4]
> > > > keepAliveTime = [300000] whenBlockedPolicy = [RUN] startUpSize = [4]
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.engine.control.CompositeCacheConfigurator
> > > > setDefaultAuxValues
> > > > INFO: Setting default auxiliaries to null
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.engine.control.CompositeCacheConfigurator
> > > > parseCompositeCacheAttributes
> > > > INFO: No special CompositeCacheAttributes class defined for key
> > > > [jcs.default.cacheattributes], using default class.
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.engine.control.CompositeCacheConfigurator
> > > > setDefaultCompositeCacheAttributes
> > > > INFO: setting defaultCompositeCacheAttributes to [ useLateral = true,
> > > > useRemote = true, useDisk = true, maxObjs = 100, maxSpoolPerRun = -1,
> > > > diskUsagePattern = SWAP, spoolChunkSize = 2 ]
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.engine.control.CompositeCacheConfigurator
> > > > parseElementAttributes
> > > > INFO: No special ElementAttribute class defined for key
> > > > [jcs.default.elementattributes], using default class.
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.engine.control.CompositeCacheConfigurator
> > > > setDefaultElementAttributes
> > > > INFO: setting defaultElementAttributes to [ IS_LATERAL = true,
> > IS_SPOOL =
> > > > true, IS_REMOTE = true, IS_ETERNAL = true, MaxLifeSeconds = -1,
> > IdleTime
> > > =
> > > > -1, CreateTime = 1442339346194, LastAccessTime = 1442339346194,
> > > > getTimeToLiveSeconds() = -1, createTime = 1442339346194 ]
> > > > Sep 15, 2015 1:49:06 PM
> > > >
> > org.apache.commons.jcs.engine.memory.AbstractDoubleLinkedListMemoryCache
> > > > initialize
> > > > INFO: initialized MemoryCache for testCache
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.engine.control.CompositeCache
> > > > <init>
> > > > INFO: Constructed cache with name [testCache] and cache attributes [
> > > > useLateral = true, useRemote = true, useDisk = true, maxObjs =
> 200001,
> > > > maxSpoolPerRun = -1, diskUsagePattern = SWAP, spoolChunkSize = 2 ]
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.engine.control.CompositeCacheConfigurator
> > > > parseAuxiliary
> > > > SEVERE: Could not instantiate auxFactory named "DC".
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.engine.control.CompositeCacheConfigurator
> > > > parseRegions
> > > > INFO: Parsed regions [testCache]
> > > > Sep 15, 2015 1:49:06 PM
> > > > org.apache.commons.jcs.engine.control.CompositeCacheConfigurator
> > > > doConfigure
> > > > INFO: Finished configuration in 13 ms.
> > > >
> > > > testCache = cacheBean.getCacheManager().getCache("testCache") also
> > > creates
> > > > a
> > > > default cache.
> > > >
> > > >
> > > >
> > > > --
> > > > View this message in context:
> > > >
> > >
> >
> http://tomee-openejb.979440.n4.nabble.com/JCache-annotations-using-default-cache-instead-of-MutableConfiguration-or-configuration-file-tp4676198p4676225.html
> > > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > > >
> > >
> >
> >
> >
> > --
> > Steven P. Goldsmith
> >
>
--
Steven P. Goldsmith