I'm using 2nd level caching with MVC3 and NHibernate.Caches.SysCache.dll like this...
1st, add a config section to your web.config file like this
<configSections>
<section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler, NHibernate.Caches.SysCache, Version=3.0.0.4000, Culture=neutral, PublicKeyToken=6876f2ea66c9f443"/>
</configSections>
add a syscache section to your web.config under your configuration section like this:
<syscache>
<cache region="SomeCustomNameRegion" expiration="86400" priority="5" />
</syscache>
in my hibernate.cfg.xml file i have the following properties added:
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
<property name="cache.use_query_cache">true</property>
<property name="cache.use_second_level_cache">true</property>
I'm using FluentNhibernate to create my mappings and add this to support caching:
public CustomerClassMap()
{
Cache.NonStrictReadWrite();
Id(x => x.Id);
Map(x => x.Name);
//... more properties
}
And then in my data access code, I have something similar to this for queries that I want cached:
public IEnumerable<Customer> GetAllCached()
{
return Session.CreateCriteria(typeof(Customer))
.SetCacheable(true)
.SetCacheRegion("SomeCustomNameRegion")
.SetCacheMode(CacheMode.Normal)
.AddOrder(Order.Desc("CreateDate"))
.List<Customer>();
}
Here are some helpful links to get into a little more detail. There's nothing specific about MVC3 that you need to worry about, and most is unchanged from earlier versions of NHibernate as far as i can tell.
http://www.klopfenstein.net/lorenz.aspx/using-syscache-as-secondary-cache-in-nhibernate
http://blog.symbiotic-development.com/2008/02/27/more-configuring-nhibernate-caches/