简体   繁体   English

如何将Hibernate二级缓存寿命设置为仅在Wildfly上部署的一个实体(Infinispan)

[英]how to set Hibernate second level cache lifespan to just one entity deploying on Wildfly (Infinispan)

Dears, 亲爱的,

How can I set Hibernate second level cache lifespan (timeout) to just one entity deploying on Wildfly (Infinispan) ? 如何将Hibernate二级缓存寿命(超时)设置为仅在Wildfly(Infinispan)上部署的一个实体?

I have an entity that is shared by some nodes (that don't know each other), all tied in a central database. 我有一个由某些节点共享的实体(彼此不认识),所有节点都绑定在中央数据库中。

I want to have a second level cache to avoid unnecessary database access. 我想要二级缓存,以避免不必要的数据库访问。 But I also want to expire this cache every 5 minutes to ensure that we have some kind of eventual consistency between nodes. 但是我也想每5分钟使此缓存过期一次,以确保节点之间具有某种最终的一致性。

So I want to configure it via second level cache. 所以我想通过二级缓存对其进行配置。

Thank you very much 非常感谢你

Infinispan is the default caching choice in Wildfly. Infinispan是Wildfly中的默认缓存选项。 Just enable the 2LC in persistence.xml ( hibernate.cache.use_second_level_cache=true ) and annotate your cached entity with javax.persistence.Cacheable . 只需在persistence.xml( hibernate.cache.use_second_level_cache=true )中启用2LC并使用javax.persistence.Cacheable注释您的缓存实体。 You can setup expiration to 5 minutes through hibernate.cache.infinispan.entity.expiration.lifespan=300 , if you want the caches to be in sync you can cluster the nodes using standalone-ha.xml . 您可以通过hibernate.cache.infinispan.entity.expiration.lifespan=300到期时间设置为5分钟,如果您希望缓存保持同步,则可以使用standalone-ha.xml集群节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM