views:

41

answers:

1

Using this, I can tell Fluent NHibernate to use SysCache as a 2nd Level Cache Provider:

MsSqlConfiguration.MsSql2008.ShowSql().ConnectionString(x =>
            {
                x.Server(@"localhost\ANDREPC");
                x.Database("mydb");
                x.TrustedConnection();
            }).Cache(c => c.ProviderClass<SysCacheProvider>().UseQueryCache())

Besides, SysCache's configurations must be placed on Web.Config:

<configuration>
 <configSections>
  <section name="syscache" type="NHibernate.Caches.SysCache.SysCacheSectionHandler,NHibernate.Caches.SysCache" />
 </configSections>

 <syscache>
  <cache region="foo" expiration="500" priority="4" />
  <cache region="bar" expiration="300" priority="3" />
 </syscache>
</configuration>

Now what? What does these regions mean? How do I associate a region with a type? How do I make this to work? My jMeter tests sugest that after the configuration above my application got 7% slower than before.. I need to understand SysCache and learn how to continue with the configuration.

Thanks.

PS: The official SysCache documentation is here and it's not explanatory

A: 

Depending on what you are doing, by default I think the L2 cache is only caching items called for by ID, E.G. session.Get or session.Load. To cache queries using ICriteria etc you need to specifically say you want that query to be cached. E.G.

ICriteria criteria = Session.CreateCriteria( ).SetCacheable( true ).SetCacheRegion( "SomeNameHere" );

The some name here is your cache region. In short this groups together cache items, Keeping this really breif I usually just put the name of the class/entity such as "Person" or "Company".

When setting up your class maps you might always want to play with the Cache property from the base class. Its something like

Cache.ReadWrite( ).IncludeAll( ) ;

I personally found that without this, when a query was executed it cached the ID's of each item in the resultset but not the items themselves, so this would make a heavy query fast, but then it has to hit the database for each item, so if you have a really simple query returning 100 items, your database could then get hit 100 times. I found that adding the above to my mapping class solved that problem.

Hopefully that helps.

cdmdotnet