title: Custom cache dependencies in NHibernate
body: <p>Anyone ever got custom cache dependencies working with NHibernate second level query cache (i.e. using overrides of the .NET CacheDependency)?</p>
  
  <p>I'm pretty sure it is not possible out-of-the-box, but I know that NHibernate is pretty hackable.</p>
  
  <p>The cache region system doesn't really support the flexibility you have when you can instantiate a cache dependency as you put data into the cache.</p>
  
  <p>Here's what the code might look like:</p>
  
  <pre><code>Session.CreateCriteria&lt;Foo&gt;("foo")
     .SetCacheable()
     .Add(Restriction.Eq("foo.Name", fooName))
     .AddCacheDependency(new MyCustomCacheDependency(fooName))
     .List&lt;Foo&gt;();
  </code></pre>