NHibernate的二级缓存问题/问题从单一的Web服务器迁移到多个Web服务器负载均衡的环境时, [英] Nhibernate 2nd level caching issues / questions when moving from a single web server to a multiple web server load balanced environment

查看:135
本文介绍了NHibernate的二级缓存问题/问题从单一的Web服务器迁移到多个Web服务器负载均衡的环境时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的previous设置了一个Web服务器和一台数据库服务器。我使用NHibernate二级缓存缓存的东西,以避免大量的呼叫要到数据库。这是我一直在使用这种本届大会伟大的工作。

My previous setup was a single web server and a single database server. I was using nhibernate 2nd level caching to cache stuff to avoid lots of calls going to the database. This has worked great as i was using this this assembly

nhibernate.caches.syscache

和添加了这个$​​ C $ c打开第二级缓存(使用常规syscache提供商):

and added this code to turn on the second level caching (using the regular syscache provider):

       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();

我现在已经迁移到具有多个Web服务器,我想了解这意味着什么一个新的环境(我仍然有一个单一的数据库服务器)。

I have now migrated over to a new environment that has multiple webservers and i am trying to understand the implications of this (I still have a single db server).

由于高速缓存被存储在Web服务器之前,现在它似乎像我有每个网络服务器2并行高速缓存,它本身可能不同步,可能会导致过时的更新等。

Since the cache was being stored on the webserver before, now it would seem like i have 2 parallel caches on each webserver which themselves may not be in sync and may cause out of date updates, etc.

什么是让我缓存了之前的好处,而且还采取提供这个新设置Web服务器负载均衡的弹性优势的最佳解决方案?

What is the best solution to get the benefits of the caching i had before but also take advantage of the resiliency of the web server load balancing that is provided with this new setup?

推荐答案

Ayende <一个href=\"http://nhibernate.hibernatingrhinos.com/28/first-and-second-level-caching-in-nhibernate\">blogged关于NHibernate的2级高速缓存的使用。您需要在Web场方案使用分布式缓存。例如SysCache2(其依赖于ASP.NET缓存并且可以被配置为使用分布式提供者)或MEMCACHE。这里是 说明如何可以配置的memcached的文章。

Ayende blogged about 2nd level cache usage in NHibernate. You will need to use a distributed cache in a web farm scenario. For example SysCache2 (which relies on ASP.NET cache and which could be configured to use a distributed provider) or MemCache. Here's an article illustrating how you could configure memcached.

这篇关于NHibernate的二级缓存问题/问题从单一的Web服务器迁移到多个Web服务器负载均衡的环境时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆