I am trying to figure out how to cache a joined query using nhibernate and it doesn't seem like its working properly
Here is my code:
public CacheTestViewModel GetCacheTestViewModel()
{
var vm = new CacheTestViewModel();
var session = Repository.Session;
using (var tx = session.BeginTransaction())
{
vm.Projects = Repository.Session.Query<Project>()
.FetchMany(r=>r.ProjectApplications)
.ThenFetch(r=>r.Application)
.Cacheable().CacheMode(CacheMode.Normal)
.ToList();
tx.Commit();
}
return vm;
}
I run this over and over again and it seems to be loading the Project objects from the second level cache but it still goes back to the db to query the ProjectApplication objects which is quite slow
Is it possible for nhibernate to cache this entire query so the whole graph get returned from cache?
NOTE: I do have the query cache turned on as well as all of the entities set with Cache.ReadWrite()
Here is my cache configuration
return configuration
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<ApplicationMap>().Conventions.Add(typeof(Conventions)))
.ExposeConfiguration(
c => {
// c.SetProperty("proxyfactory.factory_class", proxyFactory);
c.SetProperty("cache.provider_class", "NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache");
c.SetProperty("cache.use_second_level_cache", "true");
c.SetProperty("cache.use_query_cache", "true");
c.SetProperty("expiration", "86400");
})
.BuildSessionFactory();