1

我已經設法爲FHN中的Get \ Load配置二級高速緩存,但它不適用於使用ICriteria接口配置的查詢 - 它不緩存這些查詢的結果。NHibernate二級高速緩存 - 流利的nHibernate配置

有誰知道爲什麼?

的配置如下:

的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

回答

2

您是否嘗試過在配置中添加一個調用UseQueryCache()方法?

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