-->
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.  [ 8 posts ] 
Author Message
 Post subject: Cache feature requests
PostPosted: Mon Apr 26, 2004 2:39 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 2:43 pm
Posts: 22
Hi,

I wanted to present some cache feature ideas I had to present them here before putting them in JIRA, so if they are easily rejected I don't have to waste Gavin's time to reject them. ;-)

1) Method Query.setCacheable(Class) or Query.setSecondLevelCacheable(Class).

If a given Object of type Class were loaded in a query, it would be added to second level cache so that it could be loaded by id. (Class would have to be a mapped class registered w/hibernate)

2) Method Criteria.setCacheable(true)

Would work like QueryCache allowing a Criteria query to be cacheable.

3) A way to add objects to cache dynamically. Thus, say I have an Object that I want to load by SQL for some reason. I load it, I want to cache it using the same cache mechanism as the rest of the app. etc. (i.e. Session.getCacheManager().add(Object))

Is there something I am not understanding about caching theory that prevents these from being added?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 2:56 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 2:43 pm
Posts: 22
Sorry I about #1 I see from another JIRA issue that this already happens. Head still swirling about what exactly happens when with cache ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 26, 2004 9:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
#1 I don't quite undertand
#2 exists for a while now
#3 is interesting - currently native SQL queries are cacheable, so why not just use that?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 11:11 am 
Beginner
Beginner

Joined: Wed Dec 03, 2003 2:43 pm
Posts: 22
Sorry #2 is the one I realized existed.

#1 basically would cache the result sets of criteria queries like the result set of HQL queries.

Thus, if you did:

session.createCriteria(MyClass.class)
.add(Expression.eq("state", "NY"))
...
You would be able to cache the result set of this to not have to query the db everytime this criteria query were made.

#3 basically would allow Hibernate to cache either objects not loaded with hibernate (say loaded from XML). I was thinking it would also be good for caching objects created like:
select new SimpleCatData(cat.id, cat.name, count(kitten)) from cat as Cat
outer join cat.kittens as kitten.

but that can be done using cacheable queries I assume.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 27, 2004 11:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I understand #3. I still have absolutely no idea what the other thing you are asking for is.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 25, 2004 5:16 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 2:43 pm
Posts: 22
A month later...

The idea is this. Say you had a Cat object. In my understanding of Hibernate the following two actions are equivalent:

Code:
session.createCriteria(Cat.class).add(Expression.eq("name", "garfield")).add(Expression.in("kittens", kittens)).list();


and

Code:
session.createQuery("select cat from Cat as cat where cat.name=:name and cat.kittens in :kittens").setParameter("name", "garfield").setParameter("kittens", kittens).list();


However, in the below code, it is possible to add setCacheable(true) before list thus caching the result set. In the above code it is not.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 25, 2004 6:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Of course it is, there is Criteria.setCachable(true). Please read the API.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 12:48 pm 
Beginner
Beginner

Joined: Wed Dec 03, 2003 2:43 pm
Posts: 22
Wow... duh. Can't believe I missed that one. Sorry about that.


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