views:

345

answers:

1

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

+1  A: 

Have you tried adding a call to the UseQueryCache() method in the configuration?

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