了解 JBossCache - 缓存具有许多关联的对象图

发布于 2024-11-26 19:29:38 字数 628 浏览 1 评论 0原文

我正在尝试使用 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标签标记关联。我说得对吗?

但真正的问题是:

Bar​​Type 也有一些关联,这些返回对象也提供关联等等,构建了一个大的关联图。现在,我是否需要

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧城烟雨 2024-12-03 19:29:38

您想要缓存的所有实体/集合都必须具有@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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文