为什么在这个例子中没有nhibernate从缓存中检索?

leo*_*ora 5 nhibernate second-level-cache

我试图弄清楚如何使用nhibernate缓存一个连接的查询,它似乎不正常工作

这是我的代码:

   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;
    }
Run Code Online (Sandbox Code Playgroud)

我一遍又一遍地运行它似乎是从二级缓存加载Project对象但它仍然返回到db来查询ProjectApplication对象,这很慢

是否有可能nhibernate缓存整个查询,以便从缓存中返回整个图形?

注意:我确实打开了查询缓存以及使用Cache.ReadWrite()设置的所有实体

这是我的缓存配置

       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();
Run Code Online (Sandbox Code Playgroud)

Mar*_*rra 3

也许您\xc2\xb4的缓存提供程序的配置存在一些问题。I\xc2\xb4ve 能够满足您的需要,使用 Couchbase 作为二级缓存提供程序,如下所述:

\n\n

http://blog.couchbase.com/introducing-nhibernate-couchbase-2nd-level-cache-provider

\n\n

如果您的部署环境位于 Azure 上,我想这可能会有用。请注意,SysCache 模块可以\xe2\x80\x99 与 AzureMemcached 模块共存。

\n\n

http://www.webmoco.com/webmoco-development-blog/orchard-cms-second-level-caching

\n