【问题标题】:How to configure cache regions in fluent nhibernate and syscache2如何在 fluent nhibernate 和 syscache2 中配置缓存区域
【发布时间】:2010-06-03 08:48:31
【问题描述】:

我一直在尝试使用流畅的 nhibernate 实现缓存区域,到目前为止我已经完成了以下工作:

1) 在 Fluently.Configure() 中设置缓存:

private static ISessionFactory CreateSessionFactory()
{
    string csStringName = Environment.MachineName;

    var nhibConfigProps = new Dictionary<string, string>();
    nhibConfigProps.Add("current_session_context_class","web");

    var cfg = Fluently.Configure()
        .Database(MsSqlConfiguration.MsSql2008
                      .ConnectionString(c => c.FromConnectionStringWithKey(csStringName))
                      .ShowSql()
                      .Cache(cache=>cache.ProviderClass<NHibernate.Caches.SysCache2.SysCacheProvider>().UseQueryCache()))
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>())
        .ExposeConfiguration(config => config.AddProperties(nhibConfigProps))
        .ExposeConfiguration(config=> config.EventListeners.DeleteEventListeners = new IDeleteEventListener[] {new SoftDeleteListener()})
        .ExposeConfiguration(config => new SchemaUpdate(config).Execute(false, true))
        .BuildSessionFactory();

    return cfg;
}

2) 更改了我的 ClassMap 以启用缓存,并设置选择区域:

 public UserMap()
 {
     Cache.ReadWrite().Region("User");
     ...
 }

希望我已经正确地完成了上述操作,但我真的不知道在哪里配置每个区域的优先级和缓存持续时间。你知道怎么做吗?如果您碰巧发现上述代码中的缺陷,我将非常感谢您的反馈。

【问题讨论】:

    标签: c# fluent-nhibernate syscache2


    【解决方案1】:

    您需要在 web/app.config 的 syscache 配置中添加该区域的优先级和过期时间。查看this excellent post 以获得有关使用二级缓存的详细说明。这些示例使用了普通的 NHibernate,但您应该明白了 - 关于配置 syscache 的内容在帖子的末尾。

    【讨论】:

    • 好的,根据帖子我不能通过流畅的nhibernate配置缓存,所以我至少需要修复会话工厂香草风格。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    • 2014-05-25
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多