了解 JBossCache - 缓存具有许多关联的对象图
我正在尝试使用 JBossCache 作为 JPA/Hibernate 二级缓存提供程序来缓存重复调用的查询。查询返回特定类型的实体,我们将其称为 FooType。
FooType 如下所示:
@Entity(name = FooType)
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class FooType {
protected BarType barType;
@ManyToOne(targetEntity = BarType.class, cascade = {
CascadeType.ALL
})
BarType getBarType() {
return barType;
}
}
因此,Footype 具有多对一关联。现在,当我调用查询时,似乎只有很小一部分被放入缓存中。我想原因是因为我没有用@Cache标签标记关联。我说得对吗?
但真正的问题是:
BarType 也有一些关联,这些返回对象也提供关联等等,构建了一个大的关联图。现在,我是否需要
a)注释所有这些类,
b)还注释关联
以便缓存整个查询?
I'm trying to use JBossCache as a JPA/Hibernate 2nd level cache provider to cache repeatedly called queries. The queries return entities of a specific type, lets call it FooType.
FooType looks like the following:
@Entity(name = FooType)
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class FooType {
protected BarType barType;
@ManyToOne(targetEntity = BarType.class, cascade = {
CascadeType.ALL
})
BarType getBarType() {
return barType;
}
}
So, Footype has a many-to-one association. Now, when I call the query, only a very small part seems to be put in the cache. I think the reason is because I didn't mark the association with the @Cache tag. Am I correct?
But the real question is:
BarType also has a handful of associations, and these return objects which also provide associations and so on, building a big graph of associations. Now, do I need to
a) annotate all of those classes and
b) also annotate the associations
in order for the whole query to be cached?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要缓存的所有实体/集合都必须具有@Cache,以便可以缓存它们。查询缓存的工作方式略有不同,要缓存结果,您需要使查询对象可缓存。
顺便说一句,一如既往,缓存,如果它确实有意义的话!
http://docs.jboss.org /hibernate/core/3.5/reference/en/html/performance.html#performance-cache
All entities/collections you'd like to be cached must have @Cache so that they can be cached. Query cache works slightly different, to get the results cached, you need to make the query object cacheable.
Btw, as always, cache if it actually makes sense!
http://docs.jboss.org/hibernate/core/3.5/reference/en/html/performance.html#performance-cache