-->
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.  [ 7 posts ] 
Author Message
 Post subject: SysCache in (disconnected) WinForm application
PostPosted: Tue Sep 27, 2005 9:54 am 
Beginner
Beginner

Joined: Fri May 20, 2005 5:06 am
Posts: 28
I do the follwing in my app:

- create once (static) a SessionFactory

- for all Get /Create (Save) / Update / Delete I create a new session, do my command and close it

Lets take the classic customer : order = 1 : n example: if I get all customers and all orders once from the DB, then I have for each record one object in memory. If I e.g. make a lazy loading for one Customer, it gets me only the Orders from this one. The problem is, because I already loaded them before (with the get all orders statement), I now have the orders from this customer twice in the memory.

My solution to that problem currently is, that I lock all orders from which I know that they are orders from that customer in the new session, and do then the lazy loading for the customer. So I still have only one object representation of each record in memory.

In the forum I was told, I should use the 2nd lvl cache, which sounds to be a perfect (and more professional :) ) solution. So I did everything like it says in the Wiki:

App.Config: <add key="hibernate.cache.provider_class" value="NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache" />

All classes and bags: <cache usage="read-write" />

It compiles and runs without error, but it looks like it doesn't work. Any clue what I do wrong?

Another question about cache expiration: I want them as long as my session factory lives in the cache. Is this the default setting?

Thanks alot, Rainer.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 1:26 pm 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
Rainer,

The SysCacheProvider will only work when your assembly is running within the ASP.Net engine. If you want to use a second level cache in a WinForm app you will need to use the Prevalence library. Unfortunately there isn't much documentation on how to use it. Sorry.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 2:20 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Cepheus wrote:
...but it looks like it doesn't work.

Well, not much can be understood from such problem description :) But from the rest of the message, it looks like you are trying to ensure that there's only one instance of some object across your entire application. This is rather difficult to do with NHibernate and second-level cache won't help you with this. Second-level cache stores disassembled copies of objects, that is, just arrays of property values. If an object is found in second-level cache, a new object is constructed and initialized (assembled) from the disassembled values, so what you get is a fully independent copy of the original object.

The reason why second-level cache stores disassembled objects and gives out copies of objects is to avoid concurrency issues.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 4:22 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
The lack of documentation is entirely my fault. I have been extremely busy lately. Please look at the test cases in CVS and see if that helps.

tinomen wrote:
The SysCacheProvider will only work when your assembly is running within the ASP.Net engine.
Have you tried it? What error does it give you? The tests don't run under ASP.NET and they pass, so I thought it would work.

tinomen wrote:
Unfortunately there isn't much documentation on how to use it.
The only property that is configurable is "prevalenceBase", which is the directory used to cache the objects. It will default to the current directory.

Again, the lack of documentation is my fault and I apologize for that.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 5:30 pm 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
k-dub, I assumed that Prevalence wasn't documented because no one uses it.
Quote:
The tests don't run under ASP.NET and they pass, so I thought it would work.

When I first started using SysCache the logs never showed that an object was placed or retrieved from second-level cache when my DAL was used in a non-ASP.Net app. No error was thrown, it just didn't look to be used. I'll have to try it again.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 6:19 am 
Beginner
Beginner

Joined: Fri May 20, 2005 5:06 am
Posts: 28
sergey wrote:
Cepheus wrote:
...but it looks like it doesn't work.

Well, not much can be understood from such problem description :)


Sorry :oops: .

sergey wrote:
But from the rest of the message, it looks like you are trying to ensure that there's only one instance of some object across your entire application. This is rather difficult to do with NHibernate and second-level cache won't help you with this.


Hmmm. That means that my locking (i described it in more detail here: http://nhibernate.sourceforge.net/forum ... 2&start=15) is the best practice for my problem?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 4:31 pm 
Beginner
Beginner

Joined: Wed Oct 05, 2005 5:35 am
Posts: 47
Location: France
tinomen wrote:
k-dub, I assumed that Prevalence wasn't documented because no one uses it.
Quote:
The tests don't run under ASP.NET and they pass, so I thought it would work.

When I first started using SysCache the logs never showed that an object was placed or retrieved from second-level cache when my DAL was used in a non-ASP.Net app. No error was thrown, it just didn't look to be used. I'll have to try it again.


Just to confirm: SysCache works in Winforms all right. You should see it in debug log - something like:
Code:
DEBUG 5216 NHibernate.Caches.SysCache.SysCache - Fetching object 'NHibernate-Cache:d001.Business.SecurityAction:45' from the cache.
DEBUG 5216 NHibernate.Caches.SysCache.SysCache - adding new data: key=NHibernate-Cache:d001.Business.SecurityAction:45&value=Item{version=,freshTimestamp=4642347877978113}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.