简体   繁体   English

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

[英]Understanding JBossCache - Caching an object graph with many associations

I'm trying to use JBossCache as a JPA/Hibernate 2nd level cache provider to cache repeatedly called queries. 我正在尝试使用JBossCache作为JPA / Hibernate 2级缓存提供程序来缓存重复调用的查询。 The queries return entities of a specific type, lets call it FooType. 查询返回特定类型的实体,将其称为FooType。

FooType looks like the following: 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;
   }
}

So, Footype has a many-to-one association. 因此,Footype具有多对一关联。 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. 我认为原因是因为我没有使用@Cache标签标记该关联。 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. BarType也有一些关联,这些返回对象还提供关联等,从而建立了很大的关联图。 Now, do I need to 现在,我需要

a) annotate all of those classes and a)注释所有这些类,并且

b) also annotate the associations b)还要注释关联

in order for the whole query to be cached? 为了整个查询被缓存?

All entities/collections you'd like to be cached must have @Cache so that they can be cached. 您要缓存的所有实体/集合都必须具有@Cache,以便可以对其进行缓存。 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 http://docs.jboss.org/hibernate/core/3.5/reference/en/html/performance.html#performance-cache

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM