<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://nhforge.org/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>NHibernate blog : caches</title><link>http://nhforge.org/blogs/nhibernate/archive/tags/caches/default.aspx</link><description>Tags: caches</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>NHibernate Caches 2.1.0GA</title><link>http://nhforge.org/blogs/nhibernate/archive/2009/07/19/nhibernate-caches-2-1-0ga.aspx</link><pubDate>Sun, 19 Jul 2009 14:24:00 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:415</guid><dc:creator>Fabio Maulo</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://nhforge.org/blogs/nhibernate/rsscomments.aspx?PostID=415</wfw:commentRss><comments>http://nhforge.org/blogs/nhibernate/archive/2009/07/19/nhibernate-caches-2-1-0ga.aspx#comments</comments><description>&lt;p&gt;
&lt;p&gt;&lt;strong&gt;NHibernate Caches 2.1.0GA was released today.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="https://sourceforge.net/projects/nhcontrib/files/NHibernate.Caches/NHCH2.1.0GA-bin.zip/download"&gt;Download NHibernate Caches 2.1.0GA&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Enjoy it together with NHibernate2.1.0GA.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://nhforge.org/aggbug.aspx?PostID=415" width="1" height="1"&gt;</description><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/caches/default.aspx">caches</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/News/default.aspx">News</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/NH2.1/default.aspx">NH2.1</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/Release/default.aspx">Release</category></item><item><title>NHibernate Configuration</title><link>http://nhforge.org/blogs/nhibernate/archive/2009/07/17/nhibernate-configuration.aspx</link><pubDate>Fri, 17 Jul 2009 21:30:00 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:411</guid><dc:creator>Fabio Maulo</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://nhforge.org/blogs/nhibernate/rsscomments.aspx?PostID=411</wfw:commentRss><comments>http://nhforge.org/blogs/nhibernate/archive/2009/07/17/nhibernate-configuration.aspx#comments</comments><description>&lt;p&gt;[&lt;a target="_blank" href="http://fabiomaulo.blogspot.com/"&gt;My blog&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;Perhaps not so many people know in how many ways NH can be configured since NH2.0.0. In this post I&amp;rsquo;ll try to summarize some one before implement &lt;em&gt;&lt;a target="_blank" href="http://fabiomaulo.blogspot.com/2009/02/nhvloquacious-fluent-configuration-for.html"&gt;Loquacious configuration&lt;/a&gt;&lt;/em&gt; in NH3.0.0.&lt;/p&gt;
&lt;h4&gt;Xml (default)&lt;/h4&gt;
&lt;p&gt;The xml way is the most common used so only some little notes are needed here.&lt;/p&gt;
&lt;p&gt;Inside the root node, &lt;span style="color:#800000;"&gt;hibernate-configuration&lt;/span&gt;, you can configure 3 &amp;ldquo;things&amp;rdquo;: the bytecode provider, the reflection optimizer usage and the session-factory.&lt;/p&gt;
&lt;p&gt;The bytecode provider and the reflection optimizer can be configured only and exclusively inside the application config (app.config or web.config); outside application config the two configuration are ignored. If you need to configure the bytecode provider or the reflection optimizer the minimal configuration required, inside app.config is, for example:&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;hibernate-configuration &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;urn:nhibernate-configuration-2.2&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bytecode-provider &lt;/span&gt;&lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;null&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;reflection-optimizer &lt;/span&gt;&lt;span style="color:red;"&gt;use&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;false&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;hibernate-configuration&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see the &lt;span style="color:#800000;"&gt;session-factory&lt;/span&gt; section is not present (for this reason I wrote &amp;ldquo;&lt;em&gt;minimal&lt;/em&gt;&amp;rdquo;).&lt;/p&gt;
&lt;p&gt;The session-factory configuration can be wrote inside or outside the app.config or even in both (inside &lt;strong&gt;&lt;span style="text-decoration:underline;"&gt;and&lt;/span&gt;&lt;/strong&gt; outside). The minimal configuration required is:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;hibernate-configuration &lt;/span&gt;&lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;urn:nhibernate-configuration-2.2&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;session-factory &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;NHibernate.Test&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;dialect&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;NHibernate.Dialect.MsSql2005Dialect&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;proxyfactory.factory_class&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;       &lt;/span&gt;NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu&lt;br /&gt;   &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;session-factory&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;hibernate-configuration&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;As you can see there are only two properties and, as is, you can&amp;rsquo;t use this configuration because there isn&amp;rsquo;t the connection string.&lt;/p&gt;
&lt;p&gt;If you want you can write the minimal configuration inside your application config and merge/override it with the configuration wrote in an external file. I&amp;rsquo;m using this technique everywhere for tests purpose because test suite and production has some common configuration and some other different configuration (for example the &lt;span style="color:#0000ff;"&gt;current_session_context_class&lt;/span&gt;). The code to merge/override the configuration inside app.config with the configuration outside the app.config is:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;configuration = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Configuration&lt;/span&gt;()&lt;br /&gt;.Configure()&lt;br /&gt;.Configure(yourNhConfPath);&lt;/pre&gt;
&lt;p&gt;After this two lines you can continue configuring NHibernate by code (even using the method chaining).&lt;/p&gt;
&lt;h4&gt;Xml (custom configSections)&lt;/h4&gt;
&lt;p&gt;As usual in NHibernate, you can have a custom &lt;strong&gt;&lt;em&gt;Schema&lt;/em&gt;&lt;/strong&gt; for the &lt;span style="color:#800000;"&gt;hibernate-configuration&lt;/span&gt; section. The way is simple:&lt;/p&gt;
&lt;pre class="code"&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configSections&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;   &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;section &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;hibernate-configuration&lt;/span&gt;&amp;quot;&lt;br /&gt;            &lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;YourCompany.YourProduct.YourConfigurationSectionHandler, YourAssembly&lt;/span&gt;&amp;quot; &lt;span style="color:blue;"&gt;/&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;configSections&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The restriction is :&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The section name must be &amp;ldquo;hibernate-configuration&amp;rdquo;. &lt;/li&gt;
&lt;li&gt;Your ConfigurationSectionHandler must implements &lt;span style="color:#2b91af;"&gt;IHibernateConfiguration&lt;/span&gt;. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The reason to write a custom ConfigurationSectionHandler, more than implement something related to &lt;em&gt;Enterprise Library-Configuration Application Block&lt;/em&gt;, can be related with the need of some framework (your imagination may work here).&lt;/p&gt;
&lt;h4&gt;Xml : &lt;em&gt;The mystery&lt;/em&gt;&lt;/h4&gt;
&lt;p&gt;In these year I saw :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;everybody using &lt;span style="color:#a31515;"&gt;property&lt;/span&gt; &lt;/li&gt;
&lt;li&gt;somebody using the &lt;span style="color:#a31515;"&gt;mapping&lt;/span&gt; section &lt;/li&gt;
&lt;li&gt;few people using the &lt;span style="color:#a31515;"&gt;event&lt;/span&gt; and/or the &lt;span style="color:#a31515;"&gt;listener&lt;/span&gt; sections &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;absolutely nobody using the &lt;span style="color:#a31515;"&gt;class-cache&lt;/span&gt; nor &lt;span style="color:#a31515;"&gt;collection-cache&lt;/span&gt; sections&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The two sections related with the second-level-cache configuration are very useful. In general the configuration of the cache is something happening after wrote all mappings; you may have a tests suite that must work without cache and another test suite to check the behavior using second-level-cache. Even if I have changed NH2.1.0 to ignore the cache configuration, inside a class-mapping, when the &lt;span style="color:#0000ff;"&gt;cache.use_second_level_cache&lt;/span&gt; is set to &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;, the right place to configure the cache, of each class/collection, is inside the session-factory-configuration and not inside the class-mapping itself; you don&amp;rsquo;t need to modify a tested mapping only because cache and you don&amp;rsquo;t need to re-deploy class-mappings only because you need to modify/add the cache configuration of a class/collection.&lt;/p&gt;
&lt;h4&gt;Configuration by code&lt;/h4&gt;
&lt;p&gt;The whole configuration via XML can be done by pure .NET code.&lt;/p&gt;
&lt;p&gt;The bytecode provider can be set before create an instance of the &lt;span style="color:#2b91af;"&gt;Configuration&lt;/span&gt; class:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.BytecodeProvider = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;EnhancedBytecode&lt;/span&gt;(container);&lt;br /&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;cfg = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Configuration&lt;/span&gt;();&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To set properties in a no strongly typed way (mean by strings) :&lt;/p&gt;
&lt;pre class="code"&gt;configuration.SetProperty(&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.GenerateStatistics, &lt;span style="color:#a31515;"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;);&lt;br /&gt;configuration.SetProperty(&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.BatchSize, &lt;span style="color:#a31515;"&gt;&amp;quot;10&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;To set listeners in a no strongly typed way (mean by strings) :&lt;/p&gt;
&lt;pre class="code"&gt;configuration.SetListeners(&lt;span style="color:#2b91af;"&gt;ListenerType&lt;/span&gt;.PreInsert,&lt;br /&gt;&lt;span style="color:blue;"&gt;new&lt;/span&gt;[] { &lt;span style="color:#a31515;"&gt;&amp;quot;YourCompany.YourProduct.YourListener, YourAssembly&amp;quot; &lt;/span&gt;});&lt;/pre&gt;
&lt;p&gt;To set listeners in strongly typed way :&lt;/p&gt;
&lt;pre class="code"&gt;configuration.EventListeners.DeleteEventListeners =&lt;br /&gt;&lt;span style="color:blue;"&gt;new&lt;/span&gt;[] {&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ResetReadOnlyEntityDeleteListener&lt;/span&gt;()}&lt;br /&gt;.Concat(listeners.DeleteEventListeners).ToArray();&lt;/pre&gt;
&lt;p&gt;To add class-mappings the &lt;span style="color:#2b91af;"&gt;Configuration&lt;/span&gt; class has various &lt;em&gt;Add*&lt;/em&gt; methods :&lt;/p&gt;
&lt;p&gt;AddAssembly(&lt;span style="color:#2b91af;"&gt;Assembly&lt;/span&gt; assembly) 
  &lt;br /&gt;AddAssembly(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; assemblyName) 
  &lt;br /&gt;AddClass(System.&lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt; persistentClass) 
  &lt;br /&gt;AddDirectory(&lt;span style="color:#2b91af;"&gt;DirectoryInfo&lt;/span&gt; dir) 
  &lt;br /&gt;AddFile(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; xmlFile) 
  &lt;br /&gt;AddFile(&lt;span style="color:#2b91af;"&gt;FileInfo&lt;/span&gt; xmlFile) 
  &lt;br /&gt;AddXmlReader(&lt;span style="color:#2b91af;"&gt;XmlReader&lt;/span&gt; hbmReader) 
  &lt;br /&gt;AddXml(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; xml) 
  &lt;br /&gt;AddResource(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; path, &lt;span style="color:#2b91af;"&gt;Assembly&lt;/span&gt; assembly) 
  &lt;br /&gt;... 
  &lt;br /&gt;...&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; AddXml(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; xml) or AddXmlString(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; xml) mean that you can add a mapping created at run-time:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;string &lt;/span&gt;hbm =&lt;br /&gt;&lt;span style="color:#a31515;"&gt;@&amp;quot;&amp;lt;?xml version=&amp;#39;1.0&amp;#39; encoding=&amp;#39;utf-8&amp;#39; ?&amp;gt;&lt;br /&gt;           &amp;lt;hibernate-mapping xmlns=&amp;#39;urn:nhibernate-mapping-2.2&amp;#39;&lt;br /&gt;               namespace=&amp;#39;NHibernate.DomainModel&amp;#39;&lt;br /&gt;               assembly=&amp;#39;NHibernate.DomainModel&amp;#39;&amp;gt;&lt;br /&gt;               &amp;lt;class name=&amp;#39;A&amp;#39; persister=&amp;#39;A&amp;#39;&amp;gt;&lt;br /&gt;                   &amp;lt;id name=&amp;#39;Id&amp;#39;&amp;gt;&lt;br /&gt;                       &amp;lt;generator class=&amp;#39;native&amp;#39; /&amp;gt;&lt;br /&gt;                   &amp;lt;/id&amp;gt;&lt;br /&gt;               &amp;lt;/class&amp;gt;&lt;br /&gt;           &amp;lt;/hibernate-mapping&amp;gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#2b91af;"&gt;Configuration &lt;/span&gt;cfg = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Configuration&lt;/span&gt;();&lt;br /&gt;cfg.AddXmlString(hbm);&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To set second-level-cache configuration for classes and collections:&lt;/p&gt;
&lt;p&gt;SetCacheConcurrencyStrategy(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; clazz, &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; concurrencyStrategy) 
  &lt;br /&gt;SetCacheConcurrencyStrategy(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; clazz, &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; concurrencyStrategy, &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; region) 
  &lt;br /&gt;SetCollectionCacheConcurrencyStrategy(&lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; collectionRole, &lt;span style="color:#0000ff;"&gt;string&lt;/span&gt; concurrencyStrategy)&lt;/p&gt;
&lt;h4&gt;The trick of custom Dialect&lt;/h4&gt;
&lt;p&gt;Few people know this trick (perhaps only the one I&amp;rsquo;m seeing everyday in the mirror).&lt;/p&gt;
&lt;p&gt;Each Dialect has the ability to define its own &lt;em&gt;DefaultProperties&lt;/em&gt;. Inside the core, so far, we are using the &lt;em&gt;DefaultProperties&lt;/em&gt; property only for few purpose (for example to define the default driver):&lt;/p&gt;
&lt;pre class="code"&gt;DefaultProperties[&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.ConnectionDriver] =&lt;br /&gt;&lt;span style="color:#a31515;"&gt;&amp;quot;NHibernate.Driver.SqlClientDriver&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;p&gt;If you are not so scared by inherit from a dialect implemented in the core and extends it to register some functions or to change some behavior, you can use it even to define default properties:&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;YourCustomDialect &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;MsSql2005Dialect&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt;&lt;span style="color:blue;"&gt;public &lt;/span&gt;YourCustomDialect()&lt;br /&gt;{&lt;br /&gt;   DefaultProperties[&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.QuerySubstitutions] =&lt;br /&gt;       &lt;span style="color:#a31515;"&gt;&amp;quot;wahr 1, falsch 0, ja &amp;#39;J&amp;#39;, nein &amp;#39;N&amp;#39;&amp;quot;&lt;/span&gt;;&lt;br /&gt;   DefaultProperties[&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.ConnectionString] =&lt;br /&gt;       &lt;span style="color:#a31515;"&gt;&amp;quot;your connection string&amp;quot;&lt;/span&gt;;&lt;br /&gt;   DefaultProperties[&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.BatchSize] = &lt;span style="color:#a31515;"&gt;&amp;quot;50&amp;quot;&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;What we saw&lt;/h4&gt;
&lt;p&gt;Since NH2.0.0GA, you have three or four ways to configure NHibernate with merge/override from different sources.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://nhforge.org/aggbug.aspx?PostID=411" width="1" height="1"&gt;</description><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/caches/default.aspx">caches</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/configuration/default.aspx">configuration</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/fluent+configuration/default.aspx">fluent configuration</category></item><item><title>NHibernate Caches 2.1.0CR1</title><link>http://nhforge.org/blogs/nhibernate/archive/2009/07/05/nhibernate-caches-2-1-0cr1.aspx</link><pubDate>Sun, 05 Jul 2009 15:15:00 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:402</guid><dc:creator>Fabio Maulo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://nhforge.org/blogs/nhibernate/rsscomments.aspx?PostID=402</wfw:commentRss><comments>http://nhforge.org/blogs/nhibernate/archive/2009/07/05/nhibernate-caches-2-1-0cr1.aspx#comments</comments><description>&lt;p&gt;
&lt;p&gt;&lt;strong&gt;NHibernate Caches 2.1.0CR1 was released today.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="https://sourceforge.net/projects/nhcontrib/files/NHibernate.Caches/NHCH2.1.0CR1-bin.zip"&gt;Download NHibernate Caches 2.1.0CR1&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Enjoy it together with NHibernate2.1.0.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://nhforge.org/aggbug.aspx?PostID=402" width="1" height="1"&gt;</description><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/caches/default.aspx">caches</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/News/default.aspx">News</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/NH2.1/default.aspx">NH2.1</category></item><item><title>NHibernate Cache Providers 2.1.0Beta1</title><link>http://nhforge.org/blogs/nhibernate/archive/2009/06/21/nhibernate-cache-providers-2-1-0beta1.aspx</link><pubDate>Sun, 21 Jun 2009 15:52:00 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:376</guid><dc:creator>Fabio Maulo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://nhforge.org/blogs/nhibernate/rsscomments.aspx?PostID=376</wfw:commentRss><comments>http://nhforge.org/blogs/nhibernate/archive/2009/06/21/nhibernate-cache-providers-2-1-0beta1.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;NHibernate Caches 2.1.0Beta1 was released today.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://sourceforge.net/project/showfiles.php?group_id=216446&amp;amp;package_id=286204"&gt;Download NHibernate Caches 2.1.0Beta1&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Enjoy it together with NHibernate2.1.0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://nhforge.org/aggbug.aspx?PostID=376" width="1" height="1"&gt;</description><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/caches/default.aspx">caches</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/News/default.aspx">News</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/Release/default.aspx">Release</category></item><item><title>NHibernate Cache Providers 2.1.0Alpha1</title><link>http://nhforge.org/blogs/nhibernate/archive/2009/06/07/nhibernate-cache-providers-2-1-0alpha1.aspx</link><pubDate>Sun, 07 Jun 2009 17:03:00 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:360</guid><dc:creator>Fabio Maulo</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://nhforge.org/blogs/nhibernate/rsscomments.aspx?PostID=360</wfw:commentRss><comments>http://nhforge.org/blogs/nhibernate/archive/2009/06/07/nhibernate-cache-providers-2-1-0alpha1.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;NHibernate Caches 2.1.0Alpha1 was released today.&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="https://sourceforge.net/project/showfiles.php?group_id=216446&amp;amp;package_id=286204"&gt;Download NHibernate Caches 2.1.0Alpha1&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Enjoy it together with NHibernate2.1.0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://nhforge.org/aggbug.aspx?PostID=360" width="1" height="1"&gt;</description><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/caches/default.aspx">caches</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/News/default.aspx">News</category></item><item><title>NHibernate 2nd Level Cache</title><link>http://nhforge.org/blogs/nhibernate/archive/2009/04/24/nhibernate-2nd-level-cache.aspx</link><pubDate>Fri, 24 Apr 2009 12:28:00 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:259</guid><dc:creator>Ayende</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://nhforge.org/blogs/nhibernate/rsscomments.aspx?PostID=259</wfw:commentRss><comments>http://nhforge.org/blogs/nhibernate/archive/2009/04/24/nhibernate-2nd-level-cache.aspx#comments</comments><description>&lt;p&gt;NHibernate has a builtin support for caching. It sounds like a trivial feature at first, until you realize how significant it is that the underlying data access infrastructure already implements it. It means that you don’t have to worry about thread safety, propagating changes in a farm, built smart cache invalidation strategies or deal with all of the messy details that are usually along for the ride when you need to implement a non trivial infrastructure piece.&lt;/p&gt;  &lt;p&gt;And no, it isn’t as simple as just shoving a value to the cache.&lt;/p&gt;  &lt;p&gt;I spent quite a bit of time talking about this &lt;a href="http://ayende.com/Blog/archive/2008/11/13/advance-nhibernate-workshop-video.aspx"&gt;here&lt;/a&gt;, so I wouldn’t go about all the cache internals and how they work, but I’ll mention the highlights. NHibernate internally has the following sub caches:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Entity Cache &lt;/li&gt;    &lt;li&gt;Collection Cache &lt;/li&gt;    &lt;li&gt;Query Cache &lt;/li&gt;    &lt;li&gt;Timestamp Cache &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;NHibernate make use of all of them in a fairly complex way to ensure that even though we are using the cache, we are still presenting a consistent view of the cache as a mirror of the database. The actual details of how we do it can be found &lt;a href="http://ayende.com/Blog/archive/2008/01/24/NHibernate-and-the-second-level-cache-tips.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Another thing that NHibernate does for us when we update the cache is try to maintain the consistent view of the world even when using replicated caches used in a farm scenarios. This requires some support from the caching infrastructure, such as the ability to perform a hard lock on the values. Of the free caching providers for NHibernate, only Velocity support this, which means that when we evaluate a cache provider for NHibernate to be used, we need to take this into account.&lt;/p&gt;  &lt;p&gt;In general, we can pretty much ignore this, but it does have some interesting implications with regards to what are the isolation guarantees that we can make based on the cache implementation that we use, the number of machines we use and the cache concurrency strategy that we use.&lt;/p&gt;  &lt;p&gt;You can read about this &lt;a href="http://nhforge.org/doc/nh/en/index.html#performance-cache-readonly"&gt;here&lt;/a&gt; and &lt;a href="http://www.hibernate.org/hib_docs/reference/en/html/performance-cache.html"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;One thing that you should be aware of is that NHibernate currently doesn’t have transaction cache concurrency story, mostly because there is no cache provider that can give us that. As such, be aware that if you require serializable isolation level to work with your entities, you cannot use the 2nd level cache. The 2nd level cache currently guarantee only read committed (and &lt;em&gt;almost&lt;/em&gt; guarantee repeatable read if this is the isolation level that you use in the database). Note that this guarantee is made for read-write cache concurrency mode only.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://nhforge.org/aggbug.aspx?PostID=259" width="1" height="1"&gt;</description><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/caches/default.aspx">caches</category></item><item><title>Tuning NHibernate: Tolerant QueryCache</title><link>http://nhforge.org/blogs/nhibernate/archive/2009/04/17/tuning-nhibernate-tolerant-querycache.aspx</link><pubDate>Sat, 18 Apr 2009 00:05:00 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:266</guid><dc:creator>Fabio Maulo</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://nhforge.org/blogs/nhibernate/rsscomments.aspx?PostID=266</wfw:commentRss><comments>http://nhforge.org/blogs/nhibernate/archive/2009/04/17/tuning-nhibernate-tolerant-querycache.aspx#comments</comments><description>&lt;p&gt;[From &lt;a href="http://fabiomaulo.blogspot.com/"&gt;My Blog&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;Before reading this post you should know something about &lt;a href="http://nhforge.org/doc/nh/en/index.html#performance-querycache"&gt;QueryCache&lt;/a&gt; and its imply tuning NH.&lt;/p&gt;
&lt;p&gt;Resuming:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using &lt;strong&gt;&lt;span style="color:#2b91af;"&gt;IQuery&lt;/span&gt;.SetCacheable(&lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;)&lt;/strong&gt; you can put/get the entirely result of a query from the cache. &lt;/li&gt;
&lt;li&gt;The cache is automatically invalidated when the &lt;em&gt;query-space&lt;/em&gt; change (mean that the cache will be throw when an Insert/Update/Delete is executed for one of the Tables involved in the query). &lt;/li&gt;
&lt;li&gt;Using &lt;strong&gt;&lt;span style="color:#2b91af;"&gt;IQuery&lt;/span&gt;.SetCacheMode(&lt;span style="color:#2b91af;"&gt;CacheMode&lt;/span&gt;.Refresh)&lt;/strong&gt; you can force the cache refresh (for example if you need to refresh the cache after a Delete/Insert). &lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;The Case&lt;/h4&gt;
&lt;p&gt;&lt;a href="http://nhforge.org/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate/eBayShot_5F00_5611DE5B.png"&gt;&lt;img border="0" width="688" src="http://nhforge.org/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/nhibernate/eBayShot_5F00_thumb_5F00_73AB6B6D.png" alt="eBayShot" height="505" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" title="eBayShot" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;(the picture is a &lt;a href="http://www.ebay.com/"&gt;e-Bay&lt;/a&gt; snapshot)&lt;/p&gt;
&lt;p&gt;Take a look to the left side. Near each option you can see a number and I&amp;rsquo;m pretty sure that it not reflect exactly the state in the DB. That number is only &lt;em&gt;&amp;ldquo;an orientation&amp;rdquo;&lt;/em&gt; for the user probably calculated few minutes before. &lt;/p&gt;
&lt;p&gt;Now, think about the SQLs, behind the scene, and how many and how much heavy they are. A possible example for &lt;em&gt;&amp;ldquo;Album Type&amp;rdquo;, &lt;/em&gt;using HQL, could look like:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;select musicCD.AlbumType.Name, count(*) from MusicCD musicCD where musicCD.Genre = &amp;lsquo;Classical&amp;rsquo; group by musicCD.AlbumType.Name&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;How much time need each &amp;ldquo;Refine search&amp;rdquo; ?&lt;/p&gt;
&lt;p&gt;Ah&amp;hellip; but there is no problem, I&amp;rsquo;m using NHibernate and its QueryCache&amp;hellip; hmmmm&amp;hellip;&lt;/p&gt;
&lt;p&gt;Now, suppose that each time you click an article you are incrementing the number of visits of that article. What happen to your &lt;em&gt;QueryCache&lt;/em&gt; ? yes, each click the &lt;em&gt;QueryCache&lt;/em&gt; will be invalidated and thrown (the same if some users in the world insert/update/delete something in the tables involved).&lt;/p&gt;
&lt;h4&gt;The Tolerant QueryCache abstract&lt;/h4&gt;
&lt;p&gt;The Tolerant QueryCache should be an implementation of &lt;span style="color:#2b91af;"&gt;IQueryCache&lt;/span&gt; which understands, through its configuration properties, that updates, to certain tables, should not invalidate the cache of queries based on those tables.&lt;/p&gt;
&lt;p&gt;Taken the above example mean that an update to &lt;em&gt;MusicCD &lt;/em&gt;does not invalidate all &amp;ldquo;&lt;em&gt;Refine search&lt;/em&gt;&amp;rdquo; queries, if we are caching those statistics heavy queries.&lt;/p&gt;
&lt;h4&gt;The integration point&lt;/h4&gt;
&lt;p&gt;Well&amp;hellip; at this point you should know how much NHibernate is extensible and &amp;ldquo;injectable&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;For each &lt;em&gt;cache-region&lt;/em&gt; NHibernate create an instance of &lt;span style="color:#2b91af;"&gt;IQueryCache&lt;/span&gt; trough an implementation of &lt;span style="color:#2b91af;"&gt;IQueryCacheFactory&lt;/span&gt; and, as you could imagine, the &lt;span style="color:#2b91af;"&gt;IQueryCacheFactory&lt;/span&gt; concrete implementation can be injected trough session-factory configuration.&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;cache.query_cache_factory&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;YourQueryCacheFactory&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;At this point we know all we should do to have our &lt;span style="color:#2b91af;"&gt;TolerantQueryCache&lt;/span&gt; :&lt;/p&gt;
&lt;ol&gt;
  &lt;br /&gt;
&lt;li&gt;Some configuration classes to configure tolerated tables for certain regions. &lt;/li&gt;
&lt;li&gt;An implementation of &lt;span style="color:#2b91af;"&gt;IQueryCacheFactory&lt;/span&gt; to use the &lt;span style="color:#2b91af;"&gt;TolerantQueryCache&lt;/span&gt; for certain regions. &lt;/li&gt;
&lt;li&gt;The implementation of &lt;span style="color:#2b91af;"&gt;TolerantQueryCache&lt;/span&gt;. &lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;The Test&lt;/h4&gt;
&lt;p&gt;Here is only the integration test; all implementations are available in &lt;a href="http://code.google.com/p/unhaddins/"&gt;uNhAddIns&lt;/a&gt;.&lt;/p&gt;
&lt;h5&gt;Domain&lt;/h5&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MusicCD&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt; &lt;span style="color:blue;"&gt;public virtual string &lt;/span&gt;Name { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Antique&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt; &lt;span style="color:blue;"&gt;public virtual string &lt;/span&gt;Name { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;class &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;MusicCD&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;table&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;MusicCDs&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;id &lt;/span&gt;&lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;int&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;     &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;generator &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;hilo&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;&lt;br /&gt; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Name&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;class &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Antique&lt;/span&gt;&amp;quot; &lt;span style="color:red;"&gt;table&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Antiques&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;id &lt;/span&gt;&lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;int&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt;     &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;generator &lt;/span&gt;&lt;span style="color:red;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;hilo&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;&lt;br /&gt; &amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;id&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;br /&gt; &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;property &lt;/span&gt;&lt;span style="color:red;"&gt;name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;Name&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;&lt;br /&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;class&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h5&gt;Configuration&lt;/h5&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public override void &lt;/span&gt;Configure(NHibernate.Cfg.&lt;span style="color:#2b91af;"&gt;Configuration &lt;/span&gt;configuration)&lt;br /&gt;{&lt;br /&gt; &lt;span style="color:blue;"&gt;base&lt;/span&gt;.Configure(configuration);&lt;br /&gt; configuration.SetProperty(&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.GenerateStatistics, &lt;span style="color:#a31515;"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;);&lt;br /&gt; configuration.SetProperty(&lt;span style="color:#2b91af;"&gt;Environment&lt;/span&gt;.CacheProvider,&lt;br /&gt;     &lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;HashtableCacheProvider&lt;/span&gt;).AssemblyQualifiedName);&lt;br /&gt;&lt;br /&gt; configuration.QueryCache()&lt;br /&gt;     .ResolveRegion(&lt;span style="color:#a31515;"&gt;&amp;quot;SearchStatistics&amp;quot;&lt;/span&gt;)&lt;br /&gt;     .Using&amp;lt;&lt;span style="color:#2b91af;"&gt;TolerantQueryCache&lt;/span&gt;&amp;gt;()&lt;br /&gt;     .TolerantWith(&lt;span style="color:#a31515;"&gt;&amp;quot;MusicCDs&amp;quot;&lt;/span&gt;);&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The configuration is only for the &lt;em&gt;&amp;ldquo;SearchStatistics&amp;rdquo;&lt;/em&gt; region so others regions will work with the default NHibernate implementation. &lt;strong&gt;NOTE&lt;/strong&gt;: the &lt;span style="color:#2b91af;"&gt;HashtableCacheProvider&lt;/span&gt; is valid only for tests.&lt;/p&gt;
&lt;h5&gt;The test&lt;/h5&gt;
&lt;pre class="code"&gt;&lt;span style="color:green;"&gt;// Fill DB&lt;br /&gt;&lt;/span&gt;SessionFactory.EncloseInTransaction(session =&amp;gt;&lt;br /&gt;{&lt;br /&gt; &lt;span style="color:blue;"&gt;for &lt;/span&gt;(&lt;span style="color:blue;"&gt;int &lt;/span&gt;i = 0; i &amp;lt; 10; i++)&lt;br /&gt; {&lt;br /&gt;     session.Save(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MusicCD &lt;/span&gt;{ Name = &lt;span style="color:#a31515;"&gt;&amp;quot;Music&amp;quot; &lt;/span&gt;+ (i / 2) });&lt;br /&gt;     session.Save(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Antique &lt;/span&gt;{ Name = &lt;span style="color:#a31515;"&gt;&amp;quot;Antique&amp;quot; &lt;/span&gt;+ (i / 2) });&lt;br /&gt; }&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;// Queries&lt;br /&gt;&lt;/span&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;musicQuery =&lt;br /&gt; &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DetachedQuery&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;select m.Name, count(*) from MusicCD m group by m.Name&amp;quot;&lt;/span&gt;)&lt;br /&gt; .SetCacheable(&lt;span style="color:blue;"&gt;true&lt;/span&gt;)&lt;br /&gt; .SetCacheRegion(&lt;span style="color:#a31515;"&gt;&amp;quot;SearchStatistics&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;antiquesQuery =&lt;br /&gt; &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;DetachedQuery&lt;/span&gt;(&lt;span style="color:#a31515;"&gt;&amp;quot;select a.Name, count(*) from Antique a group by a.Name&amp;quot;&lt;/span&gt;)&lt;br /&gt; .SetCacheable(&lt;span style="color:blue;"&gt;true&lt;/span&gt;)&lt;br /&gt; .SetCacheRegion(&lt;span style="color:#a31515;"&gt;&amp;quot;SearchStatistics&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;// Clear SessionFactory Statistics&lt;br /&gt;&lt;/span&gt;SessionFactory.Statistics.Clear();&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;// Put in second-level-cache&lt;br /&gt;&lt;/span&gt;SessionFactory.EncloseInTransaction(session =&amp;gt;&lt;br /&gt;{&lt;br /&gt; musicQuery.GetExecutableQuery(session).List();&lt;br /&gt; antiquesQuery.GetExecutableQuery(session).List();&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;// Asserts after execution&lt;br /&gt;&lt;/span&gt;SessionFactory.Statistics.QueryCacheHitCount&lt;br /&gt; .Should(&lt;span style="color:#a31515;"&gt;&amp;quot;not hit the query cache&amp;quot;&lt;/span&gt;).Be.Equal(0);&lt;br /&gt;&lt;br /&gt;SessionFactory.Statistics.QueryExecutionCount&lt;br /&gt; .Should(&lt;span style="color:#a31515;"&gt;&amp;quot;execute both queries&amp;quot;&lt;/span&gt;).Be.Equal(2);&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;// Update both tables&lt;br /&gt;&lt;/span&gt;SessionFactory.EncloseInTransaction(session =&amp;gt;&lt;br /&gt;{&lt;br /&gt; session.Save(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MusicCD &lt;/span&gt;{ Name = &lt;span style="color:#a31515;"&gt;&amp;quot;New Music&amp;quot; &lt;/span&gt;});&lt;br /&gt; session.Save(&lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Antique &lt;/span&gt;{ Name = &lt;span style="color:#a31515;"&gt;&amp;quot;New Antique&amp;quot; &lt;/span&gt;});&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;// Clear SessionFactory Statistics again&lt;br /&gt;&lt;/span&gt;SessionFactory.Statistics.Clear();&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;// Execute both queries again&lt;br /&gt;&lt;/span&gt;SessionFactory.EncloseInTransaction(session =&amp;gt;&lt;br /&gt;{&lt;br /&gt; musicQuery.GetExecutableQuery(session).List();&lt;br /&gt; antiquesQuery.GetExecutableQuery(session).List();&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;// Asserts after execution&lt;br /&gt;&lt;/span&gt;SessionFactory.Statistics.QueryCacheHitCount&lt;br /&gt; .Should(&lt;span style="color:#a31515;"&gt;&amp;quot;Hit the query cache&amp;quot;&lt;/span&gt;).Be.Equal(1);&lt;br /&gt;&lt;br /&gt;SessionFactory.Statistics.QueryExecutionCount&lt;br /&gt; .Should(&lt;span style="color:#a31515;"&gt;&amp;quot;execute only the query for Antiques&amp;quot;&lt;/span&gt;).Be.Equal(1);&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Fine! I have changed both tables but in the second execution the result for MusicCD come from the Cache.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Code available &lt;a href="http://code.google.com/p/unhaddins/"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://nhforge.org/aggbug.aspx?PostID=266" width="1" height="1"&gt;</description><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/caches/default.aspx">caches</category><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/NHibernate/default.aspx">NHibernate</category></item><item><title>NH.Caches Beta1 Is Out!</title><link>http://nhforge.org/blogs/nhibernate/archive/2008/08/31/nh-caches-beta1-is-out.aspx</link><pubDate>Sun, 31 Aug 2008 20:21:00 GMT</pubDate><guid isPermaLink="false">45f813f2-f1c4-4eda-a619-288e3cadc793:22</guid><dc:creator>Diego Jancic</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://nhforge.org/blogs/nhibernate/rsscomments.aspx?PostID=22</wfw:commentRss><comments>http://nhforge.org/blogs/nhibernate/archive/2008/08/31/nh-caches-beta1-is-out.aspx#comments</comments><description>&lt;p&gt;The&amp;nbsp;first beta&amp;nbsp;version of NHibernate.Caches is ready to be downloaded from SourceForge! (&lt;a target="_blank" href="http://nhforge.org/media/p/6.aspx" title="Download"&gt;Download&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;To be honest, the most used caches haven&amp;#39;t major changes, just some&amp;nbsp;bug fixes, and a bit of refactoring. But, there are still some interesting things that make this&amp;nbsp;version &amp;quot;a thing that every developer&amp;nbsp;must-have&amp;quot;, let&amp;#39;s say:&lt;/p&gt;
&lt;p&gt;- Works with NH 2.0.0 GA! Not yet using it ? Check out what are you missing: &lt;a href="http://www.hibernate.org/357.html#A14"&gt;http://www.hibernate.org/357.html#A14&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;- Two new providers were added:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - indeXus.net Shared Cache - &lt;a href="http://www.sharedcache.com"&gt;http://www.sharedcache.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - Microsoft Distributed Cache (CodeName &amp;quot;Velocity&amp;quot;) - &lt;a href="http://msdn.microsoft.com/en-us/data/cc655792.aspx"&gt;http://msdn.microsoft.com/en-us/data/cc655792.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And, really thanks to dabuddhaman for the contributions!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://nhforge.org/aggbug.aspx?PostID=22" width="1" height="1"&gt;</description><category domain="http://nhforge.org/blogs/nhibernate/archive/tags/caches/default.aspx">caches</category></item></channel></rss>