簡體   English   中英

如何為 JPA L2 緩存配置 WIldfly infinispan 子系統?

[英]How to configure WIldfly infinispan subsystem for JPA L2 Cache?

我正在嘗試在 Wildfly 14 上啟用 JPA L2 緩存。即使我添加了配置緩存也沒有發生。 日志說實體正在被緩存,但在檢索它們時似乎沒有使用緩存。

我使用 Hibernate 作為 JPA 提供程序,這些是我的配置。

  • 野蠅中的standalon-ha.xml。

     <cache-container name="hibernate"> <transport lock-timeout="60000"/> <local-cache name="local-query"> <object-memory size="10000"/> <expiration max-idle="100000"/> </local-cache> <invalidation-cache name="entity"> <transaction mode="NON_XA"/> <object-memory size="10000"/> <expiration max-idle="100000"/> </invalidation-cache> <replicated-cache name="timestamps"/> </cache-container>
  • 持久性.xml

     <persistence-unit name="mysqlPersistenceUnit" transaction-type="JTA"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <!--<exclude-unlisted-classes>false</exclude-unlisted-classes>--> <shared-cache-mode>ALL</shared-cache-mode> <jta-data-source>java:/DataSourceName</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.archive.autodetection" value="class"/> <!--<property name="hibernate.show_sql" value="true"/>--> <!--<property name="hibernate.format_sql" value="true"/>--> <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/> <!-- cache --> <property name="hibernate.cache.use_second_level_cache" value="true" /> <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/> <property name="hibernate.cache.use_query_cache" value="true" /> <property name="hibernate.generate_statistics" value="true" /> <property name="hibernate.cache.infinispan.statistics" value="true"/> </properties>

  • 實體

    @Entity @Cacheable @Table(name = "table_name") public class EntityName implements Serializable { // }

這是我在執行數據庫查詢時從 Hibernate 獲得的輸出。 每次我都可以看到正在進行數據庫查詢。

[org.hibernate.engine.internal.StatisticalLoggingSessionEventListener] (default task-1) Session Metrics {
664166 nanoseconds spent acquiring 2 JDBC connections;
125120 nanoseconds spent releasing 2 JDBC connections;
1002407 nanoseconds spent preparing 2 JDBC statements;
989037118 nanoseconds spent executing 2 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
1994332 nanoseconds spent performing 2 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
366780 nanoseconds spent executing 1 flushes (flushing a total of 2 entities and 0 collections);
201076 nanoseconds spent executing 2 partial-flushes (flushing a total of 1 entities and 1 collections)

我們在此處為 WildFly 提供了 Infinispan Hibernate Cache 教程。 我強烈建議你遵循這一點。 它目前使用 WildFly 15,但應該可以與 WildFly 14 配合使用。

要知道的最重要的事情是,您不需要在persistence.xml 中定義的一半屬性。 這里

這和許多其他 Infinispan 簡單教程,可以在這里找到。 特別是,我們有簡單的教程展示了如何獨立使用 Infinispan Hibernate Cache 或在 Spring 應用程序中使用。 這些用例的配置可能略有不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM