简体   繁体   English

infinispan休眠缓存逐出

[英]infinispan hibernate cache eviction

I'm using Infinispan 6.0.0 with Hibernate 4.3.6. 我正在将Infinispan 6.0.0与Hibernate 4.3.6一起使用。

My config is: 我的配置是:

    <!-- Default configuration is appropriate for entity/collection caching. -->
   <namedCache name="entity">
      <clustering mode="invalidation">
         <stateTransfer fetchInMemoryState="false" timeout="20000"/>
         <sync replTimeout="20000"/>
      </clustering>
      <locking isolationLevel="READ_COMMITTED" concurrencyLevel="1000"
               lockAcquisitionTimeout="15000" useLockStriping="false"/>
      <!-- Eviction configuration.  WakeupInterval defines how often the eviction thread runs, in milliseconds.  
           0 means the eviction thread will never run.  A separate executor is used for eviction in each cache. -->
      <eviction maxEntries="${infinispan.maxEntries:10000}" strategy="LRU"/>
      <expiration maxIdle="${infinispan.maxIdle:-1}" wakeUpInterval="5000"/>
      <!-- <transaction transactionMode="TRANSACTIONAL" autoCommit="false"
                   lockingMode="OPTIMISTIC"/> -->
   </namedCache>

The system properties are not set, so the defaults are applied (10.000, -1). 没有设置系统属性,因此将应用默认值(10.000,-1)。

As I understand it, eviction should never happen when maxEntries is not reached. 据我了解,当未达到maxEntries时,绝不应发生驱逐。

For some of my entities the cache entries are deleted very soon after they where added to the cache. 对于我的某些实体,将高速缓存条目添加到高速缓存后很快将其删除。 The add was just a query which returns alot of these objects (< 1000). 添加只是一个查询,返回许多这些对象(<1000)。 These objects are not changed then (so no invalidation should take place). 然后,这些对象不会更改(因此不会发生无效)。

So what causes infinispan to delete the objects from the cache? 那么,是什么导致infinispan从缓存中删除对象呢?

Thank you 谢谢

I suspect that the problem you are having is that pre-Infinispan 7.2.x, eviction was done at segment level, so if the segment size reached it's limit (which is a fraction of maxEntries), then it'd kick of eviction. 我怀疑您遇到的问题是Infinispan 7.2.x之前的驱逐操作是在段级别完成的,因此,如果段大小达到其极限(这是maxEntries的一部分),那么它将被逐出。 The problem was solved in Infinispan 7.2.x as explained here . 这个问题在Infinispan的7.2.x解决的解释在这里 You should try with Infinispan 7.2.x, which should work with Hibernate 4.3. 您应该尝试使用Infinispan 7.2.x,它应该可以与Hibernate 4.3一起使用。

Yes, Hibernate does not know what is updated in native queries unless you explicitly provide that info , so it clears the entire second level cache to prevent keeping stale data. 是的,除非您显式提供该信息 ,否则Hibernate不知道本机查询中将更新的内容,因此它将清除整个二级缓存以防止保留陈旧的数据。

To tell Hibernate that the native query does not affect any data in the second level cache: 告诉Hibernate本机查询不影响二级缓存中的任何数据:

SQLQuery sqlQuery = session.createSQLQuery(" ... ");
sqlQuery.addSynchronizedQuerySpace("");  
sqlQuery.executeUpdate();

OK; 好; got it... 得到它了...

In Hibernate Query.executeUpdate() clears associated entity cache. 在Hibernate中,Query.executeUpdate()清除关联的实体缓存。

Other ORM's do the same? 其他ORM也一样吗?

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

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