简体   繁体   中英

How to clear the Infinispan cache

In my project, we use infinispan as 2nd Level cache in combination with Hibernate 4. This is the entry from the persistence.xml

<jta-data-source>java:jboss/datasources/RuleEngine</jta-data-source>        
  <shared-cache-mode>ALL</shared-cache-mode>
  <properties>
    <property name="hibernate.show_sql" value="false" />
    <property name="hibernate.dialect" value="org.hibernate.dialect.DB2390Dialect"/>
    <property name="hibernate.cache.use_second_level_cache" value="true" />
    <property name="hibernate.cache.use_query_cache" value="true"/>
    <property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/RuleEngineCache"/>
    <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"/>
  </properties>

What I wanted to do is to clear the cache when hitting a button on the GUI. The java code is:

CacheManager cm = new DefaultCacheManager();
Cache<Object, Object> c = cm.getCache();
c.clear();

I added this code to my web project.

But I get an exception on the first line saying Failed to define class org.infinispan.io.ExposedByteArrayOutputStream in Module "deployment.RuleEngineWS-ear.ear.RuleEditor-1.2.0-SNAPSHOT.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/infinispan/io/ExposedByteArrayOutputStream (Module "deployment.RuleEngineWS-ear.ear.RuleEditor-1.2.0-SNAPSHOT.war:main" from Service Module Loader)
Caused by java.lang.NoClassDefFoundError: org/jboss/marshalling/ByteOutput
Caused by java.lang.ClassNotFoundException: org.jboss.marshalling.ByteOutput

The cache itself is working properly, I just have problems explicitly accessing it. I thought that I will get the one and only CacheManager if I call new DefaulCacheManager() but then also using this Interface is deprecated.

So if I am totally on the wrong path, how can I delete my cache then?

Infinispan 5.2.6

EDIT: Also I tried injecting the CM by using several tries and especially the @Resource(lookup="java:jboss/infinispan/RuleEngineCache") annotation. But it is not injected, whether I use EmbeddedCacheManager as in the quickstart example or the deprecated CacheManager.

If you want to clear Hibernate's second level cache, regardless of the caching provider, you should call up directly to Hibernate. Calling SessionFactory.getCache().evictAllRegions should do it, without having to get your hands dirty with Infinispan.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM