6

I run my Grails application using ehcache for my 2nd level Cache and it works. I installed the ehcache plugin + cache plugin and then it doesn't. I tried almost all solutions from the internet and found no solution I keep getting Another unnamed CacheManager already exists in the same VM.

One of the possible solutions is to set p:shared=true in the EhCacheManagerFactoryBean, this works if I use an old plugin "springcache plugin from grails" but with the new plugin they use a modified version of this manager and the property shared is not available.

I tried defining a new ehcache.xml file but still I can not put inside a new name for this cache manager.

I tried changing the cache.provider class inside my DataSource.groovy to use one another EhCacheProvider such as a Singleton.

Needless to say, I tested putting a different name using DSL in different places but still no luck.

At the end I'm using the old plugin for spring cache which is deprecated. Can anybody help?

I'm using Grails 2.0.3 and ehcache-core:2.5.3.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
Gil
  • 640
  • 8
  • 14

4 Answers4

7

In the hibernate section of DataSource.groovy, make sure your cache.provider.class is up to date:

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.region.factory_class = 'grails.plugin.cache.ehcache.hibernate.BeanEhcacheRegionFactory' // For Hibernate before 4.0
    cache.region.factory_class = 'grails.plugin.cache.ehcache.hibernate.BeanEhcacheRegionFactory4' // For Hibernate before 4.0 and higher
}

I had the same problem because my cache.region.factory_class was outdated: net.sf.ehcache.hibernate.EhCacheProvider.

See http://grails-plugins.github.io/grails-cache-ehcache/guide/usage.html

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
Joshua Swink
  • 3,380
  • 3
  • 29
  • 27
  • This is the correct answer, OP please give this man his props :) – Glenn Filson Nov 23 '14 at 07:22
  • 1
    Notably, if you're getting the same error in a different Grails version, there may be a different cache factory class that you need to use for Hibernate. The release notes for your version (and any intervening versions) are always a helpful place to check (e.g. https://github.com/grails/grails-core/releases/tag/v2.4.5). – jonnybot May 19 '15 at 14:40
5

For those having this error with Grails 2.5.x, just add this to Config.groovy :

beans {
   cacheManager {
      shared = true
  }
}

This solved the problem for me.

source : https://github.com/grails/grails-core/releases/tag/v2.5.0

Pierre FABIER
  • 71
  • 1
  • 6
0

Try to use cache & cache-ehcache plugins, it works for me with some limitations. But for 2ndlevel Cache it work correctly

demon101
  • 544
  • 1
  • 11
  • 39
0

For people arriving here getting the same error as OP might consider that error might be caused by an update of a domain class at runtime (hot code swap), which is not done nicely in alle versions of Grails.

I hit this bug with Grails 2.5.4, yet with the application restart button as the only option to solve.

Sebastian Barth
  • 4,079
  • 7
  • 40
  • 59