NHibernate L2 Cache - 流畅的nHibernate配置

时间:2010-01-11 15:57:06

标签: nhibernate configuration caching fluent-nhibernate icriteria

我已经设法为FHN中的Get \ Load配置L2缓存,但它不适用于使用ICriteria接口配置的查询 - 它不会缓存这些查询的结果。

有谁知道为什么?

配置如下:

的ICriteria:

 return unitOfWork
        .CurrentSession
        .CreateCriteria(typeof(Country))
        .SetCacheable(true);

实体映射:

public sealed class CountryMap : ClassMap<Country>, IMap
{
    public CountryMap()
    {
        Table("Countries");
        Not.LazyLoad();
        Cache.ReadWrite().IncludeAll();
        Id(x => x.Id);
        Map(x => x.TwoLetter);
        Map(x => x.ThreeLetter);
        Map(x => x.Name);
    }
}

数据库属性的会话工厂配置:

return () => MsSqlConfiguration.MsSql2005
                             .ConnectionString(BuildConnectionString())
                             .ShowSql()
                             .Cache(c => c.UseQueryCache()
                                    .QueryCacheFactory<StandardQueryCacheFactory>()
                                    .ProviderClass(configuration.RepositoryCacheType)
                                    .UseMinimalPuts())
                             .FormatSql()
                             .UseReflectionOptimizer();

干杯

AWC

1 个答案:

答案 0 :(得分:2)

您是否尝试在配置中添加对UseQueryCache()方法的调用?

.Database(MsSqlConfiguration.MsSql2008
    .ConnectionString(c => c.FromConnectionStringWithKey(csStringName))
    .ShowSql()
    .Cache(cache=>cache.ProviderClass<NHibernate.Caches.SysCache2.SysCacheProvider()
    .UseQueryCache()))