我正在使用 NHibernate 3.0 配置二级缓存。二级缓存对于实体和集合效果很好,但我也有一些过滤集合的实体。
<bag name="EntityTrans" cascade="all-delete-orphan" table="EntityTrans">
<key column="entityId" not-null="true" />
<one-to-many class="MyDomain.EntityTran, MyDomain" />
<filter name="cultureFilter" condition=":cultureCode = CultureCode" />
</bag>
NHibernate 二级缓存不会缓存上述过滤后的集合。我可以在 NProf 中看到,过滤后的集合查询被发送到数据库。我的 NHibernate 配置文件具有以下条目。
<class-cache class="MyDomain.EntityTran, MuDomain" region="MyRegion" usage="read-only"/>
<collection-cache collection="MyDomain.Entity.EntityTrans" region="MyRegion" usage="read-only"/>
我是否需要添加更多内容来缓存过滤后的集合?
I am configuring 2nd level cache with NHibernate 3.0. 2nd level cache works great for Entities and Collections but I also have some Entities which have filtered collections.
<bag name="EntityTrans" cascade="all-delete-orphan" table="EntityTrans">
<key column="entityId" not-null="true" />
<one-to-many class="MyDomain.EntityTran, MyDomain" />
<filter name="cultureFilter" condition=":cultureCode = CultureCode" />
</bag>
NHibernate 2nd level caching does not cache the above filtered collection. I can see in NHProf that for filtered collection queries are sent to database. My NHibernate config file has the following entries.
<class-cache class="MyDomain.EntityTran, MuDomain" region="MyRegion" usage="read-only"/>
<collection-cache collection="MyDomain.Entity.EntityTrans" region="MyRegion" usage="read-only"/>
Do I need to add something more to cache the filtered collection?
目前 NHibernate 不支持过滤集合的二级缓存。
首先我找到了这个论坛帖子。然后我查看了代码("="">CollectionLoadContext.cs ~第 299 行)并发现以下内容:
Currently NHibernate doesn't support second level cache for filtered collections.
First I found this forum post. Then I looked through the code(CollectionLoadContext.cs ~line 299) and found the following: