Details code : ehcache.xml <cache name="ProductRelation" maxEntriesLocalHeap="8" eternal="true" overflowToDisk="false" diskPersistent="false" />
hibernate sample code : Following code in for loop String qryString = " from ProductRelation where brand in ('A21P') "; Query qry = SessionManager.currentSession().createQuery(qryString); qry.setCacheable(true); return qry.list();
Output: before caching ProductRelation TotalSize mem=0 ,disk=0 Cache Name: ProductRelation, size: 0, keylist size: >>0
Hibernate: select productrel0_.DocID as DocID0_, productrel0_.RevisionId as RevisionId0_, productrel0_.Brand as Brand0_, productrel0_.Product as Product0_, productrel0_.All_Product as All5_0_, productrel0_.SKU as SKU0_, productrel0_.ModifiedBy as ModifiedBy0_, productrel0_.DateCreated as DateCrea8_0_, productrel0_.Category as Category0_, productrel0_.Sub_Brand as Sub10_0_, productrel0_.Classification as Classif11_0_, productrel0_.DateModified as DateMod12_0_, productrel0_.CreatedBy as CreatedBy0_, productrel0_.JSONDoc as JSONDoc0_ from ProductRelation productrel0_ where brand in ('A21P') testGetProdReln Q1 : 1671 ms. Q1 output Size:10 Hibernate: select productrel0_.DocID as DocID0_0_, productrel0_.RevisionId as RevisionId0_0_, productrel0_.Brand as Brand0_0_, productrel0_.Product as Product0_0_, productrel0_.All_Product as All5_0_0_, productrel0_.SKU as SKU0_0_, productrel0_.ModifiedBy as ModifiedBy0_0_, productrel0_.DateCreated as DateCrea8_0_0_, productrel0_.Category as Category0_0_, productrel0_.Sub_Brand as Sub10_0_0_, productrel0_.Classification as Classif11_0_0_, productrel0_.DateModified as DateMod12_0_0_, productrel0_.CreatedBy as CreatedBy0_0_, productrel0_.JSONDoc as JSONDoc0_0_ from ProductRelation productrel0_ where productrel0_.DocID=? Hibernate: select productrel0_.DocID as DocID0_0_, productrel0_.RevisionId as RevisionId0_0_, productrel0_.Brand as Brand0_0_, productrel0_.Product as Product0_0_, productrel0_.All_Product as All5_0_0_, productrel0_.SKU as SKU0_0_, productrel0_.ModifiedBy as ModifiedBy0_0_, productrel0_.DateCreated as DateCrea8_0_0_, productrel0_.Category as Category0_0_, productrel0_.Sub_Brand as Sub10_0_0_, productrel0_.Classification as Classif11_0_0_, productrel0_.DateModified as DateMod12_0_0_, productrel0_.CreatedBy as CreatedBy0_0_, productrel0_.JSONDoc as JSONDoc0_0_ from ProductRelation productrel0_ where productrel0_.DocID=? Hibernate: select productrel0_.DocID as DocID0_0_, productrel0_.RevisionId as RevisionId0_0_, productrel0_.Brand as Brand0_0_, productrel0_.Product as Product0_0_, productrel0_.All_Product as All5_0_0_, productrel0_.SKU as SKU0_0_, productrel0_.ModifiedBy as ModifiedBy0_0_, productrel0_.DateCreated as DateCrea8_0_0_, productrel0_.Category as Category0_0_, productrel0_.Sub_Brand as Sub10_0_0_, productrel0_.Classification as Classif11_0_0_, productrel0_.DateModified as DateMod12_0_0_, productrel0_.CreatedBy as CreatedBy0_0_, productrel0_.JSONDoc as JSONDoc0_0_ from ProductRelation productrel0_ where productrel0_.DocID=? Hibernate: select productrel0_.DocID as DocID0_0_, productrel0_.RevisionId as RevisionId0_0_, productrel0_.Brand as Brand0_0_, productrel0_.Product as Product0_0_, productrel0_.All_Product as All5_0_0_, productrel0_.SKU as SKU0_0_, productrel0_.ModifiedBy as ModifiedBy0_0_, productrel0_.DateCreated as DateCrea8_0_0_, productrel0_.Category as Category0_0_, productrel0_.Sub_Brand as Sub10_0_0_, productrel0_.Classification as Classif11_0_0_, productrel0_.DateModified as DateMod12_0_0_, productrel0_.CreatedBy as CreatedBy0_0_, productrel0_.JSONDoc as JSONDoc0_0_ from ProductRelation productrel0_ where productrel0_.DocID=? Hibernate: select productrel0_.DocID as DocID0_0_, productrel0_.RevisionId as RevisionId0_0_, productrel0_.Brand as Brand0_0_, productrel0_.Product as Product0_0_, productrel0_.All_Product as All5_0_0_, productrel0_.SKU as SKU0_0_, productrel0_.ModifiedBy as ModifiedBy0_0_, productrel0_.DateCreated as DateCrea8_0_0_, productrel0_.Category as Category0_0_, productrel0_.Sub_Brand as Sub10_0_0_, productrel0_.Classification as Classif11_0_0_, productrel0_.DateModified as DateMod12_0_0_, productrel0_.CreatedBy as CreatedBy0_0_, productrel0_.JSONDoc as JSONDoc0_0_ from ProductRelation productrel0_ where productrel0_.DocID=? Hibernate: select productrel0_.DocID as DocID0_0_, productrel0_.RevisionId as RevisionId0_0_, productrel0_.Brand as Brand0_0_, productrel0_.Product as Product0_0_, productrel0_.All_Product as All5_0_0_, productrel0_.SKU as SKU0_0_, productrel0_.ModifiedBy as ModifiedBy0_0_, productrel0_.DateCreated as DateCrea8_0_0_, productrel0_.Category as Category0_0_, productrel0_.Sub_Brand as Sub10_0_0_, productrel0_.Classification as Classif11_0_0_, productrel0_.DateModified as DateMod12_0_0_, productrel0_.CreatedBy as CreatedBy0_0_, productrel0_.JSONDoc as JSONDoc0_0_ from ProductRelation productrel0_ where productrel0_.DocID=? Hibernate: select productrel0_.DocID as DocID0_0_, productrel0_.RevisionId as RevisionId0_0_, productrel0_.Brand as Brand0_0_, productrel0_.Product as Product0_0_, productrel0_.All_Product as All5_0_0_, productrel0_.SKU as SKU0_0_, productrel0_.ModifiedBy as ModifiedBy0_0_, productrel0_.DateCreated as DateCrea8_0_0_, productrel0_.Category as Category0_0_, productrel0_.Sub_Brand as Sub10_0_0_, productrel0_.Classification as Classif11_0_0_, productrel0_.DateModified as DateMod12_0_0_, productrel0_.CreatedBy as CreatedBy0_0_, productrel0_.JSONDoc as JSONDoc0_0_ from ProductRelation productrel0_ where productrel0_.DocID=? Hibernate: select productrel0_.DocID as DocID0_0_, productrel0_.RevisionId as RevisionId0_0_, productrel0_.Brand as Brand0_0_, productrel0_.Product as Product0_0_, productrel0_.All_Product as All5_0_0_, productrel0_.SKU as SKU0_0_, productrel0_.ModifiedBy as ModifiedBy0_0_, productrel0_.DateCreated as DateCrea8_0_0_, productrel0_.Category as Category0_0_, productrel0_.Sub_Brand as Sub10_0_0_, productrel0_.Classification as Classif11_0_0_, productrel0_.DateModified as DateMod12_0_0_, productrel0_.CreatedBy as CreatedBy0_0_, productrel0_.JSONDoc as JSONDoc0_0_ from ProductRelation productrel0_ where productrel0_.DocID=? testGetProdReln Q1 : 266 ms. Q1 output Size:10 Hibernate: select productrel0_.DocID as DocID0_, productrel0_.RevisionId as RevisionId0_, productrel0_.Brand as Brand0_, productrel0_.Product as Product0_, productrel0_.All_Product as All5_0_, productrel0_.SKU as SKU0_, productrel0_.ModifiedBy as ModifiedBy0_, productrel0_.DateCreated as DateCrea8_0_, productrel0_.Category as Category0_, productrel0_.Sub_Brand as Sub10_0_, productrel0_.Classification as Classif11_0_, productrel0_.DateModified as DateMod12_0_, productrel0_.CreatedBy as CreatedBy0_, productrel0_.JSONDoc as JSONDoc0_ from ProductRelation productrel0_ where brand in ('A21P') testGetProdReln Q1 : 31 ms. Q1 output Size:10
after cache ProductRelation TotalSize mem=10056 ,disk=0 Cache Name: ProductRelation, size: 8, keylist size: >>8 org.hibernate.cache.StandardQueryCache TotalSize mem=1800 ,disk=0 Cache Name: org.hibernate.cache.StandardQueryCache, size: 1, keylist size: >>1
How to minimize these single select query.
|