Castle ActiveRecord似乎不是缓存

时间:2011-04-05 17:16:07

标签: database caching activerecord castle-activerecord

我有一些看起来像这样的代码:

Public Shared Function FindByID(ByVal SearchID As Long) As MyClass
    If (MyClass.FindAllByProperty("ID", SearchID).Count = 0) Then Return Nothing
    Return MyClass.FindAllByProperty("ID", SearchID).First
End Function

如果我打开数据库跟踪,它似乎正在对数据库进行两次调用。我的理解是,默认情况下,ActiveRecord会缓存对象。它是否不缓存查找调用的结果?据推测,在这种情况下,我可以轻松调整我的代码只调用一次方法,但在其他情况下,我可能想在多个地方进行相同的Find()调用,如果我需要添加一些额外的状态想要存储第一个的结果。

1 个答案:

答案 0 :(得分:0)

我认为你很可能想要来自nHibernate的second level caching。您需要在配置中执行以下操作:

<configSections>
        <section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache"/>

</configSections>

    <syscache>
        <cache region="YourEntityHere" expiration="86400" priority="1"/>
        <cache region="YourOtherEntity" expiration="86400" priority="1"/>
    </syscache>
相关问题