Lorenz Cuno Klopfenstein

Posts tagged "Caching"

ASP.NET MVC logo Today I wanted to add server-side caching to Babil. I had already read different opinions and techniques to do it and one in particular was interesting: it was something like "of what use is caching if the only thing the server ever does is concatenating some strings and fetch data right out of the ASP.NET cache" (as is the case using NHibernate's second level cache). Since I have no idea, the only way to find out, as usual, is to measure.  :)

Turns out that generating a complex page takes almost as long as 200ms, while returning the same page stored inside the cache takes at most 10ms (these are the values I get on the ASP.NET server included with Visual Web Developer, I expect Babil to perform much better running on a real server and not with a debug build of course). Anyway, the difference is quite noticeable and convinced me to try and get output caching done.

More...

Posted on Thursday, January 15, 2009
Tagged as
9516 Views
150 comments posted

Disclaimer: this is a roundup of things I got from the NHibernate documentation, the ufficial forum or some random blog post, they seem to work for me but I'm not completely sure this is the "correct" way of doing things.

NHibernate logo The custom CMS I'm currently working on (and that is managing this website) relies on NHibernate as its O/RM, which currently provides two separate caching mechanisms.

The first one is the first level cache. It's a local cache to each separate NHibernate Session (a single ADO connection to the database, that usually is opened when the server receives an HTTP request and is closed again when the request is completed). NHibernate will keep all objects associated to that particular session in its cache. This cache is lost as soon as the session is disposed.

NHibernate also allows you to select one of the many cache providers you can find on NHForge.org as a second level cache. This type of cache is persistent, lives across multiple request and is used by all sessions concurrently. Roughly speaking, when an object instance is fetched from the database all values of the object are stored in the cache. When the same object is requested again, NHibernate will dehydrate the object using the values found in the cache which are associated to that particular identifier of the object.

This means that no instances are stored in the cache, but only values. As explained in the documentation, this means that if you manipulate objects loaded through NHibernate you won't risk disrupting the cache, while relationships and associations between instances will always be consistent.

More...

Posted on Monday, January 05, 2009
42689 Views
1833 comments posted
Back to Klopfenstein.net
Clemens Klopfenstein Serena Kiefer Lukas Tiberio Klopfenstein Lorenz Cuno Klopfenstein
English German