java - 如何为 JPA L2 缓存配置 WIldfly infinispan 子系统?
问题描述
我正在尝试在 Wildfly 14 上启用 JPA L2 缓存。即使我添加了配置缓存也没有发生。日志说实体正在被缓存,但在检索它们时似乎没有使用缓存。
我使用 Hibernate 作为 JPA 提供程序,这些是我的配置。
Wildfly 中的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)
解决方案
推荐阅读
- c# - 无法从 XSD 文件创建 c# 类
- python - 根据姓名和时间获取中位数
- java - Java ArrayList 的合并函数复杂度
- c# - 在将 VB.Net webservice SOAP 方法转换为 C# 时需要一些帮助
- python - 如何在 Pycharm 中使用 Numpy 修复此 Polyfit 错误?
- powershell - 在 Powershell 中使用 OpenSSL 为 300 多个服务器生成证书
- c - 为什么 fflush 不允许我的程序切换模式?
- c - 第一次循环代码后的“闹钟”中断
- php - 未找到“Aerospike”类
- amazon-web-services - 如何从 AWS 外部访问 IP?