6 Replies Latest reply on Oct 1, 2014 6:00 AM by harrykrishna

    Ehcache invalidation in Jboss 7

    smarlow

      Redirected from https://community.jboss.org/message/735465#735465 (created by Daniel Jipa)

       

      I've configured my application to use the ehcache provider, and everything seems to be in order regarding caching of entities.

      My questions is how can I invalidate that cache if database entries are updated from a different source.

      I need to get a hold of the CacheManager so I can flush the caches.

       

      Thanks

        • 1. Re: Ehcache invalidation in Jboss 7
          smarlow

          How did you integrate the ehcache provider in?  As a module in as7/modules?  Can you show the module.xml and the files that you included in that.

           

          Also, what does your persistence.xml look like?

          • 2. Re: Ehcache invalidation in Jboss 7
            danjee

            Hello,

            Thank you for your quick response. I am unable to send my persistentce.xml file today because I left the office. I think my ehcache provider is not fully working and the caching was done by infinispan. Ehcache jar was not loaded as a module but a jar in my application lib folder.

            I will get back as soon as I have a much clearer vision of my issue.

            Thanks

            • 3. Re: Ehcache invalidation in Jboss 7
              danjee

              I got it working.

               

              My persistence.xml looks like this:

               

              ....

              <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />

              <property name="net.sf.ehcache.configurationResourceName" value="ehcache.xml" />

              <property name="hibernate.cache.use_query_cache" value="true" />

              <property name="hibernate.cache.use_second_level_cache" value="true" />

              ...

              The ehcache is bundled in my ear application in the lib folder. The only problem I faced was with the ehcache.xml configuration file that needed to be loaded in a config folder in jboss modules. Is there any other solution to put the ehcache.xml inside the ear ?

              • 4. Re: Ehcache invalidation in Jboss 7
                smarlow

                Two different questions I think.  For the original question, how to invalidate the second level cache entries.  For each persistence unit, there will be a EntityManagerFactory associated with the second level cache.  You could get the EntitymanagerFactory and try to call EntityManagerFactory.getCache().evictAll().  You can enable TRACE logging for org.hibernate.SQL and see if the entities are loaded from the database or cache on the next application access.

                 

                For the other question (about ehcache.xml), where did you put the ehcache.xml file under as7/modules?

                • 5. Re: Ehcache invalidation in Jboss 7
                  danjee

                  I've placed the ehcache.xml file in a configuration folder as described here:

                   

                  https://community.jboss.org/message/721458

                   

                  and it worked. I was wondering where should I placed the ehcache inside my ear.

                   

                  Thank you,

                  Daniel

                  • 6. Re: Ehcache invalidation in Jboss 7
                    harrykrishna

                    hi Danie,

                     

                    We are migrating jboss6 to jboss7.1.1 ,we are using Ehcache .not working.is it possible custom caches at jboss7.if possible can u give the details