在我的项目中,我必须根据使用情况将不同的表数据放入不同的二级缓存。一些表需要复制缓存,而另一些表只能负担分布式缓存。 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/