-->
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.  [ 1 post ] 
Author Message
 Post subject: Testing Second Level Cache
PostPosted: Thu Mar 20, 2008 4:59 am 
Beginner
Beginner

Joined: Fri Aug 10, 2007 3:34 am
Posts: 44
I made a sample project to test nhibernate performance with second level
cache.
The classes are User ->* Blog ->* Post (->* = one-to-many)

I used SQL Profiler to check how many times the DB was hit

What I discovered:

this code
Code:
ICriteria crit = session.CreateCriteria(typeof(User)).SetCacheable(true);
IList users = crit.List();
causes a single hit on the DB with a select

if i do the same thing again:
Code:
crit = session.CreateCriteria(typeof(User)).SetCacheable(true);
users = crit.List();

the DB doesn't get hit, but i gues it could be from the first-level cache (is it?)

However, doing this
Code:
crit = session.CreateCriteria(typeof(User));//no SetCacheable(true)
users = crit.List();

the DB gets hit and i guess that's ok :D

I also tried tu cache a query and the cache worked.

The strange thing is that in this code:
Code:
crit = session.CreateCriteria(typeof(User));//no SetCacheable(true)
users = crit.List();
User u = new User("CodeMonkey");
session.Save(u);
crit.List();

the DB gets hit on the last
Code:
crit.List()

I was expecting the SLC (second level cache) gets updated
from session Save or Update. Does it depend on the cache provider?


I used MemCached for all this and the performance was weaker
than using the HashtableCacheProvider.

After doing all these tests (and more) i have a question, maybe
someone will save me some time by answearing:
is it worth using the SLC?

The documentation doesn't offer much light on the caches.
I didn't find a good sample on the net...

Any advice on this?

(sorry for my English)


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

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.