【问题标题】:Castle ActiveRecord doesn't appear to be cachingCastle ActiveRecord 似乎没有缓存
【发布时间】:2011-04-05 17:16:06
【问题描述】:

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

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 调用的结果吗?大概在这种情况下,我可以轻松地调整我的代码以仅调用该方法一次,但在其他情况下,我可能想在多个地方进行相同的 Find() 调用,如果我需要添加一些额外的状态想要存储第一个结果。

【问题讨论】:

    标签: database caching activerecord castle-activerecord


    【解决方案1】:

    我认为您很可能想要来自 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>
    

    【讨论】:

    猜你喜欢
    • 2021-11-21
    • 2020-02-24
    • 2011-11-02
    • 1970-01-01
    • 2021-03-25
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    相关资源
    最近更新 更多