cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Huss <>
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
public class AppModule  {
public void configure(Binder binder) {

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:

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
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.init(
at net.sf.ehcache.CacheManager.<init>(
... 32 more

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

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.


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