8 Replies Latest reply on May 27, 2003 5:29 PM by Corby Page

    Cache Invalidation Service

    Johannes Correa Newbie

      Hi there... Can anybody give me a short explanation about how the Cache Invalidation Service works and how to configure it?

      Thanks a lot

        • 1. Re: Cache Invalidation Service
          Corby Page Newbie

          Here is a simple use case to get you started:

          You have two servers, One and Two, running in a cluster, and both deploy the same CMP 2.0 entity bean with commit-option A.

          Add the following lines to your jboss.xml for the CMP bean:

          <configuration-name>Standard CMP 2.x EntityBean with cache
          invalidation</configuration-name>
          <cache-invalidation>True</cache-invalidation>

          Now, deploy. Whenever Server One changes the state of one or more instances of your bean and commits the transaction, it will propagate messages to Server Two telling it to pull the beans with these keys out of the cache. Next time Server Two needs to access those instances, it will re-synchronize with the database.

          No, I am not on crack. Yes, it is that freaking simple.

          Sacha is da bomb.

          • 2. Re: Cache Invalidation Service
            Manish Parikh Newbie

            How do i programmatically invalidate a read only entity bean?

            • 3. Re: Cache Invalidation Service
              Corby Page Newbie

              I am assuming your question is how to invalidate specific instances of the entity bean. To invalidate the entire bean, just recycle it.

              Configure your read-only entity bean as described above so that it becomes associated with an InvalidationGroup. Then invoke the batchInvalidate() operation on the InvalidationManager MBean to selectively remove instances of the bean from the cache.

              • 4. Re: Cache Invalidation Service
                Manish Parikh Newbie

                Can you point me to a code snippet which shows how to call a MBean method : specifically calling the invalidation service

                • 5. Re: Cache Invalidation Service
                  Corby Page Newbie

                  The method signature for batchInvalidate() is complex enough that I don't have time to jot out an example right now, but I'd strongly recommend that you purchase the Admin-Devel guide for good usage examples of invoking the JBoss MBeans.

                  If you won't pick up the guide, search the source code (or google) for usages of the MBeanServer.invoke( ... ) method.

                  • 6. Re: Cache Invalidation Service
                    Manish Parikh Newbie

                    Does the invalidation service work for BMP beans also?

                    • 7. Re: Cache Invalidation Service
                      Johannes Correa Newbie

                      > Here is a simple use case to get you started:
                      >
                      > You have two servers, One and Two, running in a
                      > cluster, and both deploy the same CMP 2.0 entity bean
                      > with commit-option A.
                      >
                      > Add the following lines to your jboss.xml for the CMP
                      > bean:
                      >
                      > <configuration-name>Standard CMP 2.x EntityBean with
                      > cache
                      > invalidation</configuration-name>
                      > <cache-invalidation>True</cache-invalidation>
                      >
                      > Now, deploy. Whenever Server One changes the state of
                      > one or more instances of your bean and commits the
                      > transaction, it will propagate messages to Server Two
                      > telling it to pull the beans with these keys out of
                      > the cache. Next time Server Two needs to access those
                      > instances, it will re-synchronize with the database.
                      >
                      > No, I am not on crack. Yes, it is that freaking
                      > simple.
                      >
                      > Sacha is da bomb.
                      >

                      Hello, and a lot of thanks by your answer... I have a little doubt about it, Does it works if i have just one server?

                      Thanks again

                      Johannes

                      • 8. Re: Cache Invalidation Service
                        Corby Page Newbie

                        You don't need to configure special services to achieve 'cache invalidation' with a single server. That's just how the container has to work per the spec. The cache invalidation service is for coordinating the state of the caches between multiple servers.

                        In response to the earlier question, yes, you can configure your own 'BMP with Cache Invalidation' container in standardjboss.xml. I haven't tried it, though.