从单个Web服务器迁移到多个Web服务器负载平衡环境时,Nhibernate二级缓存问题/问题

leo*_*ora 8 nhibernate asp.net-mvc load-balancing fluent-nhibernate second-level-cache

我之前的设置是单个Web服务器和单个数据库服务器.我正在使用nhibernate二级缓存来缓存内容,以避免大量调用进入数据库.这很有用,因为我正在使用这个组件

nhibernate.caches.syscache
Run Code Online (Sandbox Code Playgroud)

并添加此代码以打开二级缓存(使用常规syscache提供程序):

       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)

我现在已迁移到具有多个Web服务器的新环境,并且我正在尝试了解其含义(我仍然有一个数据库服务器).

由于缓存之前存储在Web服务器上,现在看起来我在每个Web服务器上都有2个并行缓存,它们本身可能不同步并且可能导致过时更新等.

获得之前缓存的好处的最佳解决方案是什么,还可以利用此新设置提供的Web服务器负载平衡的弹性?

Dar*_*rov 8

Ayende 在NHibernate上发表了关于二级缓存使用情况的博文.您将需要在Web场方案中使用分布式缓存.例如,SysCache2(它依赖于ASP.NET缓存,可以配置为使用分布式提供程序)或MemCache.这是一篇说明如何配置memcached 的文章.