Hibernate & EHCache : how does maxElementsInMemory work?

后端 未结 1 691
夕颜
夕颜 2021-02-01 07:03

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 update

相关标签:
1条回答
  • 2021-02-01 07:54

    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.

    0 讨论(0)
提交回复
热议问题