what is in cache is the result of the query not the single entity
2010/2/27 Chuck Boyde <[email protected]>
> 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:
>
> var acc = session.CreateQuery("from
> Account").SetCacheable(true).List();
>
> I have set the following in the config:
> <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:
> [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:
>
> [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);
> }
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>
--
Fabio Maulo
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.