-
1. Re: Understanding query and entity cahce
suikast42 Oct 18, 2012 5:27 AM (in response to suikast42)Ok I think (or I hope) I'm little bit smarter now.
The query cahce will cahce the results with the same query for example:
Query Cache
["from Person as p where p.parent.id=? and p.firstName=?", [ 1 , "Joey"] ] -> [ 2 ] ]
So any query like above will return the result from the cache. For this I must set query.setCacheable(true); right ??
The entity cache will only cache the Id based access on the entity.
*-----------------------------------------------------*
| Person Data Cache |
|-----------------------------------------------------|
| 1 -> [ "Giblbert" , "Q" , "Public" , null , [ 2 , 3 ] ] |
| 2 -> [ "Joey" , "D" , "Public" , 1 , [] ] |
| 3 -> [ "Sara" , "N" , "Public" , 1 , [] ] |
*-----------------------------------------------------*
personDAO.getById(1) --> For the same session this entity is cahced in L1. If I do a session.clear() or commit the transaction then the result comes from L2 cache.
personDAO.getByName("Gilbert") --> Excecute every time a SQL query. ( The query is not cached )
Are my assumptions right ?