休眠& EHCache:maxElementsInMemory如何工作? [英] Hibernate & EHCache : how does maxElementsInMemory work?

查看:179
本文介绍了休眠& EHCache:maxElementsInMemory如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为EHCache配置了一个defaultCache(用于元素),一个StandardQueryCache(用于查询)和UpdateTimestampsCache(用于我所追踪的数据库更新......但我并没有真正了解它所做的事情)。

我为这些缓存中的每一个设置了maxElementsInMemory,但是我没有得到的是这个数字为StandardQueryCache和UpdateTimestampsCache控制的内容。我得到可以在默认缓存中缓存的实体数量不能超过10000,但查询缓存不会缓存元素。它缓存主键(据我所知)。那么这是否意味着StandardQueryCache的maxElementsInMemory控制结果中行的数量,还是它控制它可能具有的元素的主键对的数量?

UpdateTimestampsCache怎么样?它是否记录了实体上次更新,上次更新表或其他内容的时间?我应该为maxElementsInMemory使用哪一个号码?

谢谢!

 < ehcache xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi:noNamespaceSchemaLocation =ehcache.xsdupdateCheck =truemonitoring =autodetectdynamicConfig =true > 
< defaultCache
maxElementsInMemory =10000
eternal =false
timeToIdleSeconds =3600
timeToLiveSeconds =3600>
< / defaultCache>

< cache
name =org.hibernate.cache.internal.StandardQueryCache
maxElementsInMemory =10000
eternal =false
timeToIdleSeconds =3600
timeToLiveSeconds =3600>
< / cache>

< cache
name =org.hibernate.cache.spi.UpdateTimestampsCache
maxElementsInMemory =10000
eternal =true>
< / cache>

< / ehcache>


解决方案

对于查询缓存,每个查询结果的结果是StandardQueryCache区域中的一个条目。因此,您的缓存目前已设置为在默认/未命名区域中缓存10000个不同的查询结果。查询设置为使用命名区域(Query#setCacheRegion)写入不同的缓存区域。



每当底层数据发生更改时,这些结果都需要无效。这是UpdateTimestampsCache的目的。当Hibernate写入表时,它会将条目写入UpdateTimestampsCache(只有在启用查询缓存时才启用此进程,因为它显式地使这些缓存的查询结果无效)。在回读高速缓存的查询结果时,我们使用查询结果缓存的时间戳检查所有表使用的表的时间戳,以确定结果是否仍然有效。如果可能,最好不要限制这个区域。如果您需要,最佳数字是您的基础域模型中的表的数量。否则,当不需要时,缓存的查询结果可能开始失效。很难想象你有10000张桌子,所以你可能在那里很好。


I've configured EHCache with a defaultCache (for elements), a StandardQueryCache (for queries) and UpdateTimestampsCache (for what I believe is to keep track of database updates...but I don't really get what it excactly does).

I've set the maxElementsInMemory for each of these caches, but what I don't get is what this number controls for the StandardQueryCache and for the UpdateTimestampsCache. I get that the number of entities that can be cached in the default cache must not exceed 10000, but the query cache does not cache elements. It caches primary keys (as far as I understand).

Does this then mean that the maxElementsInMemory for the StandardQueryCache controls the number of "rows" from results, or does it control the number of primary key pairs for elements it may have?

What about the UpdateTimestampsCache? Does it keep track of the last time an entity was updated, the last time a table was updated...or something else? What number should I use for maxElementsInMemory for this one?

Thanks!

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect"     dynamicConfig="true">
  <defaultCache 
    maxElementsInMemory="10000"
    eternal="false"
    timeToIdleSeconds="3600"
    timeToLiveSeconds="3600">
  </defaultCache>

  <cache
    name="org.hibernate.cache.internal.StandardQueryCache"
    maxElementsInMemory="10000"
    eternal="false"
    timeToIdleSeconds="3600"
    timeToLiveSeconds="3600">
  </cache>

  <cache
    name="org.hibernate.cache.spi.UpdateTimestampsCache"
    maxElementsInMemory="10000"
    eternal="true">
  </cache>

</ehcache>

解决方案

For query caching, the results from each query result is one entry in the StandardQueryCache region. So your cache there is currently set up to cache 10000 different query results in the default/unnamed region. Queries set to use a named region (Query#setCacheRegion) write to a different cache region.

These results need to be "invalidated" whenever the underlying data is changed. That is the purpose of UpdateTimestampsCache. When Hibernate writes to tables it makes entries into the UpdateTimestampsCache (this process is only enabled when the query cache is enabled as it is explicitly part of invalidating these cached query results). When reading back cached query results, we check the timestamp cached with the query results against the timestamps of all the tables it uses to determine if the results are still valid. Its best really to not limit this region if possible. If you need to, the best number is the number of tables in your underlying domain model. Otherwise, cached query results might start getting invalidated when not necesary. Hard to imagine you have 10000 tables though, so you are probably fine there.

这篇关于休眠&amp; EHCache:maxElementsInMemory如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆