NHibernate L2 Cache - fluent nHibernate configuration
- by AWC
I've managed to configure the L2 cache for Get\Load in FHN, but it's not working for queries configured using the ICriteria interface - it doesn't cache the results from these queries.
Does anyone know why?
The configurations are as follows:
ICriteria:
return unitOfWork
.CurrentSession
.CreateCriteria(typeof(Country))
.SetCacheable(true);
Entity Mapping:
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);
}
}
And the session factory configuration for the database property:
return () => MsSqlConfiguration.MsSql2005
.ConnectionString(BuildConnectionString())
.ShowSql()
.Cache(c => c.UseQueryCache()
.QueryCacheFactory<StandardQueryCacheFactory>()
.ProviderClass(configuration.RepositoryCacheType)
.UseMinimalPuts())
.FormatSql()
.UseReflectionOptimizer();
Cheers
AWC