I have enabled the level2 cache for one of my old project "Asset Management".
here are some important points to use the L2 cache:
1. add this line to web.config nhibernate section
<add key="hibernate.cache.provider_class"
value="NHibernate.Caches.SysCache.SysCacheProvider,NHibernate.Caches.SysCache" />
<add key="relativeExpiration" value="300" />
2. NHibernate.Caches.SysCache.dll have different version. it can be download from nhibernate contribution.
I didn't have one to match my nhibernate version, if you can't found the right version, you download the source code and rebuilt it with the current nhibernate.
3. example of set entity definition file *.hbm
<class name="eg.Cat" .... >
<cache usage="read-write"/>
....
<set name="Kittens" ... >
<cache usage="read-write"/>
....
</set>
</class>
There are readonly|read-write|nonstrict-read-write strategies.
readonly for entities never be modified.
nonstrict-read-write for entities be update occasionally(don't need worry about two trsaction update same entity)
4. the query cache is not recommended, because it stateless, but good for query the "readonly" database tables
<add key="hibernate.cache.use_query_cache" value="true" />
IList blogs = sess.CreateQuery("from Blog blog where blog.Blogger = :blogger")
.SetEntity("blogger", blogger)
.SetMaxResults(15)
.SetCacheable(true)
.SetCacheRegion("frontpages")
.List();
call IQuery.SetForceCacheRefresh(true) to reload the query, it is particularly if the table is updated outside of the nhibernate.
for the current Castle ActiveRecord, the nhibernate is 1.2, here is the doc:
http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/caches.html
http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/...
http://using.castleproject.org/display/AR/Enable+second+level+cache
to understand how Level2 cache working:
http://ayende.com/Blog/category/510.aspx