为什么NHibernate在第二次请求时不使用二级缓存?

为什么NHibernate在第二次请求时不使用二级缓存?,nhibernate,caching,syscache,Nhibernate,Caching,Syscache,我有下面的型号 <class name="Navigation" table="`navigation`"> <cache usage="nonstrict-read-write" region="LongTerm" /> <id name="Id" column="`navigation_id`" type="Int16" unsaved-value="0"> <generator class="native" /&g

我有下面的型号

<class name="Navigation" table="`navigation`">
    <cache usage="nonstrict-read-write" region="LongTerm" />

    <id name="Id" column="`navigation_id`" type="Int16" unsaved-value="0">
        <generator class="native" />
    </id>

    <property name="Name" column="`navigation_name`" type="String" not-null="true" />
    <property name="DateCreated" column="`navigation_date-created`" type="DateTime" not-null="true" />
    <property name="DateSaved" column="`navigation_date-saved`" type="DateTime" not-null="true" />
    <property name="Active" column="`navigation_active`" type="Boolean" not-null="true" />
    <property name="RestrictToWebMaster" column="`navigation_web-master-restrict`" type="Boolean" not-null="true" />

    <many-to-one name="User" column="user_id" class="User" />

    <set name="Items" order-by="`navigation-item_index` asc" inverse="true" cascade="all-delete-orphan">
        <cache usage="nonstrict-read-write" region="LongTerm" />

        <key column="`navigation_id`" />
        <one-to-many class="Navigation+Item" />
    </set>
</class>

然后我有一个test.aspx查询集合

DataProvider provider = new DataProvider(SessionManager.GetSession());

protected void Page_Load(object sender, EventArgs e)
{
    IList<Navigation> navs = provider.Session.QueryOver<Navigation>()
        .Cacheable()
        .List();

    foreach (Navigation nav in navs) {
        litTest.Text += nav.Name + "<br />";
    }
}
DataProvider-provider=newdataprovider(SessionManager.GetSession());
受保护的无效页面加载(对象发送方、事件参数e)
{
IList navs=provider.Session.QueryOver()
.Cacheable()
.List();
foreach(导航中的导航){
litTest.Text+=nav.Name+“
”; } }
当我重新加载页面时,查询将重新运行。为什么不从缓存中检索数据?

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2-x-factories">
    <session-factory name="Default">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>

        <property name="current_session_context_class">web</property>
        <property name="show_sql">true</property>

        <property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
        <property name="cache.use_query_cache">true</property>
        <property name="cache.use_second_level_cache">true</property>
    </session-factory>
</hibernate-configuration>

<syscache>
    <cache region="LongTerm" expiration="3600" priority="5" />
    <cache region="MediumTerm" expiration="900" priority="3" />
    <cache region="ShortTerm" expiration="180" priority="1" />
</syscache>

NHibernate.Connection.DriverConnectionProvider
NHibernate.dialogue.mssql2008dialogue
NHibernate.Driver.SqlClientDriver
网状物
符合事实的
NHibernate.Caches.SysCache.SysCacheProvider,NHibernate.Caches.SysCache
符合事实的
符合事实的

您应该在事务中运行此操作,并在最后提交事务


仅当事务已成功提交时,NHibernate才会更新二级缓存。如果不启动NHibernate事务,NHibernate将不知道结果是否足以缓存。

您应该在事务中运行此操作,并在最后提交事务


仅当事务已成功提交时,NHibernate才会更新二级缓存。如果不启动NHibernate事务,NHibernate将不知道结果是否足以缓存。

这是事实!谢谢,这是事实!谢谢