4 Replies Latest reply on Oct 29, 2010 6:56 AM by henk de boer

    JPA 2nd level cache question

    George Georgieff Newbie

      If we are using Infinispan for 2nd level cache for JPA providers, is Infinispan expected to cache the "select count(a) from A a where b > :b" query result?

       

      Thanks.

       

      P.S. I need the performance for this query to be O(nealy 1).

        • 1. Re: JPA 2nd level cache question
          Sanne Grinovero Master

          Hi,

          yes it's expected to do that, but seems more a Hibernate (general) related question, this is not something specific to Infinispan 2nd level cache but of any 2nd level cache.

          Make sure you enable the query cache (globally) and enable caching on the query instance.

          Also keep in mind that this cache is going to be invalidated each time a A is inserted/removed.

          • 2. Re: JPA 2nd level cache question
            George Georgieff Newbie

            Well I am not that into the Hibernate internals. I am using the JPA technology. Hibernate should be left out as an implementation detail here.

             

            If the query cache is enabled globally, must I enable query cache for each query ?

            And do you mean this cache entry (the count) is going to be invalidated, or do you mean if an A is added then the entire cluster wide cache with all entries of all classes ever created in the life of the entire cluster are invalidated ?

             

            Thanks

            • 3. Re: JPA 2nd level cache question
              Sanne Grinovero Master

              Well I am not that into the Hibernate internals. I am using the JPA technology. Hibernate should be left out as an implementation detail here

              sure, but you still might want to read the manual relating to Hibernate specific features, such as caching.

               

              If the query cache is enabled globally, must I enable query cache for each query ?

              yes; I'd suggest to enable SQL statements logging, so that you can verify what and when is cached with trivial testing

              And do you mean this cache entry (the count) is going to be invalidated, or do you mean if an A is added then the entire cluster wide cache with all entries of all classes ever created in the life of the entire cluster are invalidated ?

              only the query count or other queries related to A(s) are invalidated, specific cache entries related to other instances of A (as per a different primary key) or any other type are unaffected.

              • 4. Re: JPA 2nd level cache question
                henk de boer Master

                Sanne Grinovero wrote:

                 

                Well I am not that into the Hibernate internals. I am using the JPA technology. Hibernate should be left out as an implementation detail here

                sure, but you still might want to read the manual relating to Hibernate specific features, such as caching.

                 

                Of course caching itself (including 2nd level cache and query caching) is part of the core JPA specification, but configuring a caching provider for a specific JPA provider is still proprietary I think.