asp.net - 二级缓存不缓存NHibernate中过滤的集合?

标签 asp.net hibernate nhibernate second-level-cache

我正在使用 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 2 级缓存不缓存上述过滤集合。我可以在 NProf 中看到过滤集合查询被发送到数据库。我的 NHibernate 配置文件有以下条目。

<class-cache class="MyDomain.EntityTran, MuDomain" region="MyRegion" usage="read-only"/>
<collection-cache collection="MyDomain.Entity.EntityTrans" region="MyRegion" usage="read-only"/>

是否需要添加更多内容来缓存过滤后的集合?

最佳答案

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

首先我发现了 forum post .然后我查看了代码(CollectionLoadContext.cs ~line 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!!!!!
}

关于asp.net - 二级缓存不缓存NHibernate中过滤的集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6228764/

相关文章:

jquery - "The state information is invalid for this page and might be corrupted"

asp.net - Web服务,Web方法和服务器端代码之间的区别?

java - Spring JPA在多对多关系中持久化子级时如何持久化父级

nhibernate - 无法从NHibernate.Driver.SQLite20Driver创建驱动程序

没有ID的NHibernate映射

javascript - 未在 Javascript 函数中获取 HTML 文本框值?已搜索,但没有找到令人信服的答案

c# - asp.net aspx OnClick 在客户端服务进行中单击时不会触发

java - 在具有 hibernate 功能的模型(域)类中使用枚举 - 无法解析属性 - 异常

hibernate - c3p0 创建的连接数多于配置中指定的连接数

asp.net-mvc - NHibernate与 Entity Framework [已关闭]