java - Hibernate为不同的表提供不同的缓存?

标签 java hibernate infinispan second-level-cache

在我的项目中,我必须根据使用情况将不同的表数据放入不同的二级缓存。一些表需要复制缓存,而另一些表只能负担分布式缓存。 hibernate 可以进行这种配置吗?

在 hibernate.properties 中我们只能指定一个缓存

 hibernate.cache.infinispan.entity.cfg=replicated-cache-entity
 hibernate.cache.infinispan.collection.cfg=replicated-cache-entity

此缓存在 ininispan.xml 中配置

   <namedCache name="replicated-cache-entity">
       <clustering mode="replication">
           <stateRetrieval fetchInMemoryState="false" timeout="20000"/>
           <sync replTimeout="20000"/>
       </clustering>
   </namedCache>

有没有办法为单个表或类指定不同的缓存(infinispan 中的缓存名称)?

或者

有没有办法像 infinispan 拦截器一样拦截 hibernate L2 缓存调用?

最佳答案

Infinispan user guide还提到了每个实体的缓存配置:

On top of that, this finer grained cache definition enables users to define cache settings on a per entity/collection basis. For example:

<!-- If using Hibernate, add to your hibernate.cfg.xml --> 
<property name="hibernate.cache.infinispan.com.acme.Person.cfg">   
  person-entity
</property> 
<property name="hibernate.cache.infinispan.com.acme.Person.addresses.cfg">   
  addresses-collection
</property>

关于java - Hibernate为不同的表提供不同的缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28668971/

相关文章:

java - Infinispan如何用于数据持久化?

java - 将 Infinispan xml 配置从 6.x 迁移到 7.x

mysql - 排序和分页

java - Infinispan,如何确保键/缓存上的读写锁定

java - 不同的 setText(CharSequence,TextView.BufferType) 和 setText(CharSequence)

java - Spring Cloud config - 共享文件或其位置

java - 在 Java 中如何通过名称获取字段或方法?

java - 当将弱引用或软引用与ReferenceQueue一起使用时,对象何时真正从内存中删除?

java - 如何使用 gwt RequestFactory 机制来持久化 HashMap ( map )?

java - Spring 与 hibernate : Duplicate entry for key 'PRIMARY'