Spring Hibernate With EhCache

Ehcache is an open-source, standards-based cache for boosting performance, simplifying scalability and offloading your database. EhCache is used to improve performance by reducing the load on underlying resources.  It can also be used for RESTful server caching, application persistence, and distributed caching.

In simple words, cache means a store of things that will be required in future, and can be retrieved rapidly.

How much will an application speed up with Caching?

It depends on the multitude of factors being:

  1. At what level, data present in cache can and is reused by the application.
  2. The proportion of response time that is ease by caching.

Spring contains cache manager interface org.springframework.cache.CacheManager, so we need to provide concrete implementation for cache storage.

One of the implementations for caching is : EhCache.

This project involves Ehcache in Spring with hibernate configuration. It follows Model View Controller ( MVC ) architecture.

Firstly take a maven project in eclipse using webapp archetype.

Project Structure

Maven dependency

Add this maven dependency in your application’s classpath to implement ehcache in your project :

Configuring the cache storage

Controller class

DAO Implementation

Create a ehcache.xml file, to tell Ehcache how and where to cache the data.

To get all data, execute these queries in MySQL Database :


You can download the code from here : Download

Leave a Reply