3

在升级到 NHibernate 3.2 之前,我为 Fluent NHibernate 使用了以下代码:

OracleClientConfiguration configurer = (OracleClientConfiguration.Oracle10.ShowSql().ConnectionString(c =>
                         c.FromConnectionStringWithKey(ConnectionString.Development))
                         .DefaultSchema("MySchema")
                         .UseReflectionOptimizer()
          /* Here --> */ .Cache(c => 
                                 c.ProviderClass<SysCacheProvider>()
                                 .UseQueryCache()));

但是,.Cache()在 NHibernate 3.2 中不再找到扩展方法。

我将如何设置我的缓存提供程序?

编辑:我也试过:

        .ExposeConfiguration(configuration =>
        {
            configuration.SetProperty(Environment.UseQueryCache, "true");
            configuration.SetProperty(Environment.CacheProvider, "NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache2");
        });
4

2 回答 2

6

这是我使用 SysCache 提供程序的配置的摘录。

var configuration = new Configuration()
    .Cache(x => x.UseQueryCache = true)
configuration.SessionFactory()
    .Caching.Through<SysCacheProvider>().WithDefaultExpiration(60)
于 2012-04-02T19:31:52.773 回答
0

http://www.markhneedham.com/blog/2010/06/16/fluent-nhibernate-and-the-2nd-level-cache/ & https://web.archive.org/web/20110514214657/http: //blogs.hibernatingrhinos.com/nhibernate/archive/2008/11/09/first-and-second-level-caching-in-nhibernate.aspx

一个常见错误(我也遇到过!)是在向数据库添加或更改实体/聚合时忘记提交或省略事务。如果我们现在从另一个会话访问实体/聚合,那么二级缓存将不会准备好为我们提供缓存的实例,并且 NHibernate 会进行一次(意外的数据库往返)。

我也有同样的问题,google了很多遍,终于看到了。坏消息是,我尝试使用 trasaction,但打开二级缓存仍然失败!

于 2013-06-01T01:08:38.123 回答