NHibernate in Action - Impressive chapter on caching

written by tobinharris on November 13th, 2008 @ 07:53 PM

I'm currently editing Chapter 5 for NHibernate in Action (we hope to be in print in a 2-4 weeks, so this is the last time!).

Chapter 5 is about transactions and caching. There's a lot of information on the 2nd level cache, including process-scoped and cluster-scoped caches for distributed scenarios.

Despite that I've reviewed/edited this chapter a few times, I've not used NHibernate's 2nd level cache until recently. So I'm reviewing and learning at the same time!

Hats off to the original authors and Pierre Henri for writing such a strong chapter. The case-study style scenarios are particularly useful for working out optimal caching strategies.

For example, I just learnt that an app I'm working on could benefit from the nonstric-read-write cache usage:

<cache usage="nonstrict-read-write"/>

....instead of...

<cache usage="read-write"/>

Nonstrict-read-write means that when you save an object to the database, NHibernate will invalidate it in the cache too, but it does it asynchronously meaning there's no guarantee of exactly when it's removed from the cache. Of course, this introduces the chance that another process could read stale data from the cache (albeit only a few milliseconds stale!). This is a tradeoff, and the benefit is performance - because it's asynchronous NHibernate won't wait for both DB and Cache to confirm the changes.

I'm looking forward to benchmarking the various caching options to see just how much my app can gain.

Right now my 2nd level cache is provided by the ASP.NET Session Cache, but in a few weeks I'm hoping to switch to a distributed cluster of Velocity caches. That will be fun!...



kick it on DotNetKicks.com



Comments

  • Ben Scheirman on 13 Nov 22:11

    Tobin,

    What’s the plan for a 2nd edition of this book? I’m sure it’s on everyone’s mind that NHibernate 2.0GA has shipped, and includes many breaking changes from 1.2. I’ve been looking forward to this book for over a year, but now that NH 2.0 is out, I’ll be looking forward to the 2nd ed.

    Any news?

  • Eric on 14 Nov 22:19

    I have also been awaiting this book for a while. I assumed part of the delay was to update the content for NHibernate 2.0GA. Is this not the case?

  • Tobin Harris on 15 Nov 06:11

    @Eric

    Unfortunately, makeing the book fully NHibernate 2.0 compatible would have meant basically re-editing & proofing the entire book, thus delaying it even more.

    We’ve had great reviews from many early access readers, and believe the book still has a ton of value, even though it’s targetted at 1.2.1GA.

    But yeah, I wish we could have crammed in the 2.0 stuff :-( If time permits, we’ll add a chapter/appendix covering as much of that stuff as possible.

    @Ben

    I haven’t personally talked to anyone about 2nd edition yet.

    I see you’re working on ASP.NET MVC in Action btw. Sounds great :)

Post a comment

Options:

Size

Colors