The test results: 2010-02-28 12:05:23,046 INFO Started Logging
First Query 2010-02-28 12:05:23,156 DEBUG SELECT this_.Id as Id11_0_, this_.Version as Version11_0_, this_.Name as Name11_0_ FROM Promoters this_ NHibernate: SELECT this_.Id as Id11_0_, this_.Version as Version11_0_, this_.Name as Name11_0_ FROM Promoters this_ Second Query Third Query 2010-02-28 12:05:23,315 DEBUG SELECT this_.Id as Id11_0_, this_.Version as Version11_0_, this_.Name as Name11_0_ FROM Promoters this_ NHibernate: SELECT this_.Id as Id11_0_, this_.Version as Version11_0_, this_.Name as Name11_0_ FROM Promoters this_ Fourth Query 2010-02-28 12:05:23,318 DEBUG SELECT this_.Id as Id11_0_, this_.Version as Version11_0_, this_.Name as Name11_0_ FROM Promoters this_ NHibernate: SELECT this_.Id as Id11_0_, this_.Version as Version11_0_, this_.Name as Name11_0_ FROM Promoters this_ On Feb 28, 12:21 pm, Chuck Boyde <[email protected]> wrote: > thanks for the reply Fabio. I understand that the values are cached. > My issue is that the following: > var query = session.Linq<Promoter>(); > query.QueryOptions.SetCachable(true); > query.QueryOptions.SetCacheMode(CacheMode.Normal); > var p = query.ToList(); > > will place the items into the cache as expected and subsequest queries > will use the cache. BUT the following will not hit the cache and > always hits the database: > > var query = session.Linq<Promoter>(); > query.QueryOptions.SetCachable(true); > query.QueryOptions.SetCacheMode(CacheMode.Normal); > var p = query.Select(x=>x).ToList(); > > Don't understand this behaviour. My fluent config: > > Fluently.Configure() > .Database(MsSqlConfiguration.MsSql2008 > > .ConnectionString(ConfigurationService.SqlConnectionString) > .ShowSql() > .Cache(c => c > .UseQueryCache() > > .ProviderClass(typeof(NHibernate.Cache.HashtableCacheProvider).AssemblyQualifiedName))// > for test purposes > ) > .Mappings(m => > m.FluentMappings.AddFromAssemblyOf<EventMap>() > > .Conventions.Setup(MappingConventions.GetConventions())) > .ExposeConfiguration(BuildSchema) > .BuildSessionFactory(); > > My Test: > [Test] > public void Can_Use_Cache() > { > ISessionFactory factory = > Storage.Application.Get<ISessionFactory>("SessionFactory"); > // initial hit on the database and load into cache > using (var session = factory.OpenSession()) > { > Console.WriteLine(""); > Console.WriteLine("First Query"); > var query = session.Linq<Promoter>(); > query.QueryOptions.SetCachable(true); > query.QueryOptions.SetCacheMode(CacheMode.Normal); > var p = query.ToList(); > } > // no hit on the database and retrieved from cache as > expected > using (var session = factory.OpenSession()) > { > Console.WriteLine(""); > Console.WriteLine("Second Query"); > var query = session.Linq<Promoter>(); > query.QueryOptions.SetCachable(true); > query.QueryOptions.SetCacheMode(CacheMode.Normal); > var p = query.ToList(); > } > // hits the db - should have come from the cache > using (var session = factory.OpenSession()) > { > Console.WriteLine(""); > Console.WriteLine("Third Query"); > var query = session.Linq<Promoter>(); > query.QueryOptions.SetCachable(true); > query.QueryOptions.SetCacheMode(CacheMode.Normal); > var p = query.Select(x=>x).ToList(); > } > // hits the db again - should have come from the cache > using (var session = factory.OpenSession()) > { > Console.WriteLine(""); > Console.WriteLine("Fourth Query"); > var query = session.Linq<Promoter>(); > query.QueryOptions.SetCachable(true); > query.QueryOptions.SetCacheMode(CacheMode.Normal); > var p = query.Select(x => x).ToList(); > } > } > > On Feb 27, 10:49 pm, Fabio Maulo <[email protected]> wrote: > > > 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.
