NHibernate 中二级缓存不缓存过滤后的集合?

发布于 11-13 05:22 字数 829 浏览 6 评论 0 原文

我正在使用 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

流心雨 2024-11-20 05:22:44

目前 NHibernate 不支持过滤集合的二级缓存。

首先我找到了这个论坛帖子。然后我查看了代码("="">CollectionLoadContext.cs ~第 299 行)并发现以下内容:

if (!(session.EnabledFilters.Count == 0) && persister.IsAffectedByEnabledFilters(session))
{
    // some filters affecting the collection are enabled on the session, so do not do the put into the cache.
    log.Debug("Refusing to add to cache due to enabled filters");
    // todo : add the notion of enabled filters to the CacheKey to differentiate filtered collections from non-filtered;
    //      but CacheKey is currently used for both collections and entities; would ideally need to define two separate ones;
    //      currently this works in conjunction with the check on
    //      DefaultInitializeCollectionEventHandler.initializeCollectionFromCache() (which makes sure to not read from
    //      cache with enabled filters).
    return; // EARLY EXIT!!!!!
}

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:

if (!(session.EnabledFilters.Count == 0) && persister.IsAffectedByEnabledFilters(session))
{
    // some filters affecting the collection are enabled on the session, so do not do the put into the cache.
    log.Debug("Refusing to add to cache due to enabled filters");
    // todo : add the notion of enabled filters to the CacheKey to differentiate filtered collections from non-filtered;
    //      but CacheKey is currently used for both collections and entities; would ideally need to define two separate ones;
    //      currently this works in conjunction with the check on
    //      DefaultInitializeCollectionEventHandler.initializeCollectionFromCache() (which makes sure to not read from
    //      cache with enabled filters).
    return; // EARLY EXIT!!!!!
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文