在网上找的例子http://www.cnblogs.com/tenghoo/archive/2009/12/09/NHibernate_memcache.html
参照这个搞了一个 Nhibernate+memcached 的demo 遇到问题了, 所有的配置都是按照这个来的, 项目运行起来没问题,每次请求数据都会从memcached请求, 但是memcached里一直没有数据。。。然后就直接跑到数据库读取数据去了。
<?xml version="1.0" encoding="utf-8"?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > <session-factory name="NHibernate.Test"> <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="connection.connection_string"> Data Source=192.168.1.129;Initial Catalog=authority_bj;uid=sa;password=gxtLxx1!; </property> <property name="adonet.batch_size">10</property> <property name="show_sql">false</property> <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property> <property name="command_timeout">60</property> <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> <property name="cache.provider_class">NHibernate.Caches.MemCache.MemCacheProvider,NHibernate.Caches.MemCache</property> <property name="cache.use_second_level_cache">true</property> <property name="cache.use_query_cache">true</property> <property name="cache.default_expiration">300</property> <property name="cache.region_prefix">prefix</property> <mapping assembly="HibernateModel"/> <class-cache class="HibernateModel.Warrant_BaseInfo,HibernateModel" usage="read-write" /> </session-factory> </hibernate-configuration>
Memcached.ClientLibrary.SockIOPool pool = Memcached.ClientLibrary.SockIOPool.GetInstance(); System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(@"hibernate.cfg.xml"); ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure(xmlReader).BuildSessionFactory(); using (ISession session = factory.OpenSession()) { long lngID = 1; var sss = session.Get<HibernateModel.Warrant_BaseInfo>(lngID); } using (ISession session = factory.OpenSession()) { long lngID = 1; var sss = session.Get<HibernateModel.Warrant_BaseInfo>(lngID); }
页面刷新一次 会增加两次get请求。 但是实际上memcached里面根本就木有数据。。。
谁能帮我看看这是为啥啊。