Hi, I am working with the second level cache and I am using the
default Hashtable as I am just testing this feature.
I have configured the hibernate.cfg.xml in the following way:

    <property
name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider</
property>
    <!-- You have to explicitly enable the second level cache -->
    <property name="cache.use_second_level_cache">true</property>
    <!-- cache will expire in 2 minutes -->
    <property name="cache.default_expiration">120</property>
    <!-- I want also to cache queries -->
    <property name="cache.use_query_cache">true</property>

And I have configured my entity to be cachable in the following way:

  <class
      name="CachableProduct"
      table="[CachableProduct]"
      dynamic-insert="true"
      dynamic-update="true">
    <cache usage="read-write"/>
    <id name="ProductId">
      <generator class="guid.comb" />
    </id>
    <property name="Name">

    </property>
    <property name="Price">

    </property>
  </class>

When I try to run the following unit test, it always print out two
SELECT statements, so it clearly doesn't cache the entity. But if I
write a unit test calling Load<T> or Get<T> from two different
sessions, the 2nd level cache works, so I believe I have an issue just
with the query cache.

            using (var session = factory.OpenSession())
            {
                using (var tx =
session.BeginTransaction(IsolationLevel.ReadCommitted))
                {
                    Console.WriteLine("*** FIRST SESSION ***");
                    var result = session
                        .CreateCriteria(typeof(CachableProduct))
                        .SetCacheable(true)
                        .Add(Restrictions.Eq("Name", "PC"))
                        .List<CachableProduct>();
                    tx.Commit();
                }
            }
            using (var session = factory.OpenSession())
            {
                using (var tx =
session.BeginTransaction(IsolationLevel.ReadCommitted))
                {
                    Console.WriteLine("*** SECOND SESSION ***");
                    var result = session
                        .CreateCriteria(typeof(CachableProduct))
                        .SetCacheable(true)
                        .Add(Restrictions.Eq("Name", "PC"))
                        .List<CachableProduct>();
                    tx.Commit();
                }
            }

-- 
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.

Reply via email to