Hi all
I have come across a problem and don't believe this is by design. I am
unable to get nhibernate to use the cache when using a query like:
Code:
var acc = session.CreateQuery("from Account").SetCacheable(true).List();
I have set the following in the config:
Code:
<property name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache" >true</property>
My test:
Code:
[Test]
public void Can_Cache_Query()
{
Console.WriteLine("1st query");
using (var session = SessionFactory.OpenSession())
{
var acc = session.CreateQuery("from Account").SetCacheable(true).List();
acc.ShouldNotBeNull();
}
Console.WriteLine("2nd query");
using (var session = SessionFactory.OpenSession())
{
var acc = session.CreateQuery("from Account").SetCacheable(true).List();
acc.ShouldNotBeNull();
}
}
unless I use session.Get, which works fine, the query hits the db
instead of the cache. This is ok:
Code:
[Test]
public void account_should_be_in_second_level_cache()
{
using (var session = SessionFactory.OpenSession())
{
Console.WriteLine("--> Now loading account");
var acc = session.Get<Account>(newAccount.Id);
acc.ShouldNotBeNull();
acc.Name.ShouldEqual(newAccount.Name);
}
}
Going nuts here