cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <johnth...@gmail.com>
Subject QueryCache injection problem with multiple runtimes
Date Thu, 23 Jun 2016 22:03:47 GMT
I'm starting to use QueryCache for the first time, and I'm using EhCache
since OSCache is a dead product.  My app creates two separate runtimes that
are identical, but separate.  If I configure both to use EhCache with the
module:
public class AppModule  {
public void configure(Binder binder) {
binder.bind(QueryCache.class).to(EhCacheQueryCache.class);
        }
}

then the app fails to start because the cache can't be created twice with
the same name (see below).

I thought I could ditch the injection and just set it directly:

runtime.getDataDomain().setQueryCache(queryCache);
But this actually does *nothing*.  The DataContextFactory uses the
QueryCache that was set by the injector and ignores this later
modification.  This method should be removed or even better - made to work.

org.apache.cayenne.di.DIRuntimeException: Error instantiating class
'org.apache.cayenne.cache.EhCacheQueryCache'
at
org.apache.cayenne.di.spi.ConstructorInjectingProvider.get(ConstructorInjectingProvider.java:144)
...
Caused by: net.sf.ehcache.CacheException: *Another CacheManager with same
name 'MyCache' already exists in the same VM. Please provide unique names
for each CacheManager in the config or do one of following:*
*1. Use one of the CacheManager.create() static factory methods to reuse
same CacheManager with same name or create one if necessary*
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: DefaultConfigurationSource [
ehcache.xml or ehcache-failsafe.xml ]
at
net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:628)
at net.sf.ehcache.CacheManager.init(CacheManager.java:392)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:375)
at
org.apache.cayenne.cache.EhCacheQueryCache.<init>(EhCacheQueryCache.java:46)
... 32 more



If I change the EhCacheQueryCache to follow the suggestion in the error it
looks like this:
    public MyEhCacheQueryCache() {
        cacheManager = CacheManager.getInstance();
        init();
    }

This fixes the problem, but I'm not sure it's the right behavior.  This
will result in the same query cache instance being shared among all the
runtimes, which I'm guessing isn't how it is supposed to work.

John

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message