I'm benchmarking the performance gains from using a 2nd level cache in Hibernate (enabling EhCache), but it doesn't seem to improve performance. In fact, the time to perform the query slightly increases.
The query is:
session.createCriteria(MyEntity.class).list();
The entity is:
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MyEntity {
@Id
@GeneratedValue
private long id;
@Column(length=5000)
private String data;
//---SNIP getters and setters---
}
My hibernate.cfg.xml is:
<!-- all the normal stuff to get it to connect & map the entities plus:-->
<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.EhCacheRegionFactory
</property>
The MyEntity table contains about 2000 rows.
The problem is that before adding in the cache, the query above to list all entities took an average of 65 ms. After the cache, they take an average of 74 ms. Is there something I'm missing? Is there something extra that needs to be done that will increase performance?