Tôi cố gắng để tìm ra cách để cache một truy vấn tham gia sử dụng nhibernate và nó không có vẻ như làm việc của nó đúngTại sao không nhibernate lấy từ bộ nhớ cache trong ví dụ này?
Đây là mã của tôi:
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;
}
tôi chạy này hơn và hơn nữa và nó có vẻ là tải các đối tượng dự án từ bộ nhớ cache mức thứ hai nhưng nó vẫn quay ngược lại db để truy vấn các đối tượng ProjectApplication đó là khá chậm
có thể cho nhibernate để cache toàn bộ truy vấn này để toàn bộ đồ thị có được trả lại từ bộ nhớ cache?
Chú ý: Tôi không có bộ nhớ cache truy vấn bật cũng như tất cả các thực thể thiết lập với Cache.ReadWrite()
Dưới đây là cấu hình bộ nhớ cache của tôi
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();
Bạn có thể hiển thị cấu hình bộ nhớ cache của mình không? – Najera
@Najera - Tôi đã thêm cấu hình bộ nhớ cache của mình – leora