首页 > 解决方案 > 如何为 JPA L2 缓存配置 WIldfly infinispan 子系统?

问题描述

我正在尝试在 Wildfly 14 上启用 JPA L2 缓存。即使我添加了配置缓存也没有发生。日志说实体正在被缓存,但在检索它们时似乎没有使用缓存。

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

这是我在执行数据库查询时从 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)

标签: javahibernatejpawildflyinfinispan

解决方案


我们在这里有一个用于 WildFly 的 Infinispan Hibernate Cache 教程。我强烈建议你遵循这一点。它目前使用 WildFly 15,但应该可以正常使用 WildFly 14。

要知道的最重要的事情是,您不需要在 persistence.xml 中定义的一半属性。见这里

这个和许多其他 Infinispan 简单教程都可以在这里找到。特别是,我们有简单的教程展示如何独立使用 Infinispan Hibernate Cache 或在 Spring 应用程序中使用。这些用例的配置可能略有不同。


推荐阅读