spring数据jpa中redis如何提供二级缓存?

How to provide second level cache with redis in spring data jpa?

如何在spring数据jpa中用redis提供二级缓存?

不仅是hibernate,希望所有的jpa provider都能使用这个缓存

有人可以帮忙吗?

这取决于具有 spring-data-jpa 的应用程序使用的 JPA 实现库。我将谈论 2 个流行的 JPA 实现:Hibernate 和 Eclipselink。

Eclipselink 只能使用其自己的二级缓存提供程序,因此无法将 Redis 用作二级缓存。

Hibernate 提供了将第 3 方缓存库用作第 2 级缓存提供程序的能力。最新的 Hibernate 5.1 内置了对两个缓存库的支持:Ehcache 和 Infinispan:Hibernate documentation. There are proprietary and open source libraries supporting other caching providers including Redis: GitHub: debop/hibernate-redis.