These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: using the second-level cache
PostPosted: Thu Jun 21, 2007 2:08 pm 
Newbie

Joined: Thu Dec 22, 2005 10:21 pm
Posts: 4
I've been evaluating using nhibernate for the data-access layer to an ASP.NET 2.0 web-service app. I'm having issues with caching; instead of grabbing the objects in the second-level cache (syscache2), it's "hydrating" them using n "selects", then realizing n times that the "Item was already cached".

I've been reading the docs on using the second-level cache, but I think I'm still a bit confused. What does "hydrating" mean? Is the above behaviour by-design? Shouldn't it check the cache first, see whether the objects have expired (by time and/or perhaps by a Sql 2005 notification), and only if necessary hit the database (and, when it does need to refresh, should it do n-selects)?

How do I use the command from the web.config file (below), or is that done automatically? How can I be notified when an object is evicted from the cache (eg: Sql 2005 notifies the app a change occured)?

thanks!!
--craig


Hibernate version: 1.2

Mapping documents:

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="StandardMix,DAL" table="standard_mixes" lazy="false">
<cache usage="read-write" region="MyCacheRegion" />
<id name="Id" column="id" type="int">
<generator class="assigned" />
</id>
<property name="Title" column="title" type="string" not-null="true" />
<property name="Genre" column="genre" type="string" not-null="true" />
<property name="Type" column="type" type="string" not-null="true" />
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Name and version of the database you are using: Sql Server 2005

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

20:52:39.242 [9] DEBUG NHibernate.Loader.Loader - Hydrating entity: DAL.StandardMix#765
...
20:52:39.289 [9] DEBUG NHibernate.Loader.Loader - total objects hydrated: 96
20:52:39.289 [9] DEBUG NHibernate.Impl.SessionImpl - resolving associations for: [DAL.StandardMix#765]
20:52:39.289 [9] DEBUG NHibernate.Impl.SessionImpl - adding entity to second-level cache [DAL.StandardMix#765]
20:52:39.289 [9] DEBUG NHibernate.Cache.ReadWriteCache - Caching: DAL.StandardMix, MyServiceDAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null#765
...
20:52:43.637 [9] DEBUG NHibernate.Loader.Loader - Initializing object from DataReader: [DAL.StandardMix#765]
20:52:43.637 [9] DEBUG NHibernate.Loader.Loader - Hydrating entity: DAL.StandardMix#765
...
20:52:43.668 [9] DEBUG NHibernate.Loader.Loader - total objects hydrated: 96
20:52:43.668 [9] DEBUG NHibernate.Impl.SessionImpl - resolving associations for: [DAL.StandardMix#765]
20:52:43.668 [9] DEBUG NHibernate.Impl.SessionImpl - adding entity to second-level cache [DAL.StandardMix#765]
20:52:43.668 [9] DEBUG NHibernate.Cache.ReadWriteCache - Caching: DAL.StandardMix, MyServiceDAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null#765
20:52:43.668 [9] DEBUG NHibernate.Caches.SysCache2.SysCacheRegion - Fetching object 'NHibernate-Cache:MyCacheRegion:DAL.StandardMix, MyServiceDAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null#765@765' from the cache.
20:52:43.668 [9] DEBUG NHibernate.Cache.ReadWriteCache - Item was already cached: DAL.StandardMix, MyServiceDAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null#765
20:52:43.668 [9] DEBUG NHibernate.Impl.SessionImpl - done materializing entity [DAL.StandardMix#765]
20:52:43.668 [9] DEBUG NHibernate.Impl.SessionImpl - resolving associations for: [DAL.StandardMix#819]
20:52:43.668 [9] DEBUG NHibernate.Impl.SessionImpl - adding entity to second-level cache [DAL.StandardMix#819]

------

here's the config for my web.config file:

<sysCache>
<cacheRegion name="MyCacheRegion" relativeExpiration="25" priority="High" >
<dependencies>
<commands>
<add name="DAL.StandardMix"
command="SELECT [id],[title],[genre],[type] FROM [dbo].[standard_mixes]"
connectionName="MyDb"
connectionStringProviderType="NHibernate.Caches.SysCache2.ConfigConnectionStringProvider, NHibernate.Caches.SysCache2"
/>
</commands>
</dependencies>
</cacheRegion>
</sysCache>


Top
 Profile  
 
 Post subject: Re: using the second-level cache
PostPosted: Fri Jun 22, 2007 8:44 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
craigp wrote:
Shouldn't it check the cache first, see whether the objects have expired (by time and/or perhaps by a Sql 2005 notification), and only if necessary hit the database (and, when it does need to refresh, should it do n-selects)?


Didn't you forget to enable caching? It is done in the NH configuration options and it seems to me that it is not enough to specify caching strategy in the class mapping...

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.