我有这样一个相当简单的数据模型:Ehcache - 为什么这些条目如此之大?
class MyParent {
// 7 fields here, some numeric, some String, not longer than 50 chars total
Set<MyChild> children;
}
class MyChild {
int ownerId;
// 3 more fields, numeric or dates
}
MyParent
,MyChild
和MyParent.children
都缓存与read-only
。
我有40,000个MyParent
的实例和MyChild
的100,000个实例。这会在缓存中产生180,000个条目(如果添加40,000个MyParent.children
)。我想缓存一切,按ownerId
分组。不想推倒重来,我想用查询缓存,如:
Query query = session
.createQuery(
"select distinct p from MyParent p join fetch p.children c where c.ownerId = :ownerId");
query.setParameter("ownerId", ownerId);
query.setCacheable(true);
query.setCacheRegion("MyRegion");
query.list();
对于ownerId
所有1500倍的值。
缓存工作,但我注意到它是巨大的!用Ehcache.calculateInMemorySize()
来衡量,平均每个条目超过一千字节大。为了缓存〜180,000个条目,我需要超过200 MB。考虑到参赛作品本身要小得多,那就太过分了。
开销从哪里来,我该如何减少它?