Ok, I figured it out. I ran my named query using the following syntax:
IQuery q = session.GetNamedQuery("MyQuery") .SetResultTransformer(Transformers.AliasToBean(typeof(MyDTO))) .SetCacheable(true) .SetCacheRegion("MyCacheRegion");
(which, I could add, EXACTLY how NHibernate tells you how to do it .. but I get distracted;))
If you use the creation of a new AliasToBean Transformer for each request, each request object (which is the key to the cache) will be unique and you will never get a cache hit. So, in short, if you do this, as nhib docs say, then caching will not work.
Instead, create your transformer once in the static var element, and then use it for your request, and caching will work - for example:
private static IResultTransformer myTransformer = Transformers.AliasToBean(typeof(MyDTO))
...
IQuery q = session.GetNamedQuery("MyQuery") .SetResultTransformer(myTransformer) .SetCacheable(true) .SetCacheRegion("MyCacheRegion");
source share