Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query Level Cache

 
lavnish lalchandani
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I understand difference between 1st level and 2nd level cache.
Wanted to understand How is query level cache different from 1st and 2nd Level Cache

as per my understanding if i run a query with ? ie
from employee emp where emp.id=?

then only it can be cached in a 2nd Level cache … so query like
from employee emp where emp.id=123

will not be cached .. to cache these a query cache is used , right ?

BUT in my code if i have queries as below ... do we see one DB hit or Two DB hit
from employee emp where emp.id=123


from employee e where e.id=123
// extra spaces in query string + e used instead of emp
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following Link may guide you precisely
Hibernate Cache Strategies

All The Best
 
Salil Vverma
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi lavnish,

Second level cache stores the object in a map, having primary key as Map's key and Object as map value. Second level cache is used only while accessing the object by primary key ie by using session.get(), session.load().

Query cache store the query result in map, having query and its parameters as Map's key and result as map value. Query cache can be used to cache & reuse the result of any query irrespective of primary key usage in it.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic