NHibernate L2 Cache - fluent nHibernate configuration

Posted by AWC on Stack Overflow See other posts from Stack Overflow or by AWC
Published on 2010-01-11T15:57:06Z Indexed on 2010/06/03 8:14 UTC
Read the original article Hit count: 846

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

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about configuration