1.0 Introduction to Ehcache
Ehcache is the most widely used open-source java based cache, used to boost performance of a web application. It supports integration compatibility with many frameworks. Any Database operation that is redundant can be stored in cache, so that result is stored in the cache after first Database hits.
Later on, further calls will be made to cache, and the result will be retrieved from Cache, instead of Database calls. This in turn, optimizes the Application.
Example: Some configurations data, master data from Database can be stored in cache.
1.1 Configuration Steps
Put ehcache-xx.jar in the Project lib folder. (Current Latest jar is 3.5.2, as of Aug, 2018)
Ehcache jars can be downloaded from here.
Step 2
Place ehcache.xml file in the Project classpath location. (Sample xml)
Step 3
Create a CacheManager.java file. Inside this class, Define a method with @Cacheable as shown
below:
class CacheManager{
@Cacheable("cacheData")
public String getCacheData(){
...
...
// DAO calls or API calls results are stored.
...
}
}
Step 4
Make entry of this method in ehcache.xml file.
Sample is as shown below:
Step 5
Thats is the end of Ehcache configuration.
Ehcache jars can be downloaded from here.
Step 2
Place ehcache.xml file in the Project classpath location. (Sample xml)
Step 3
Create a CacheManager.java file. Inside this class, Define a method with @Cacheable as shown
below:
class CacheManager{
@Cacheable("cacheData")
public String getCacheData(){
...
...
// DAO calls or API calls results are stored.
...
}
}
Step 4
Make entry of this method in ehcache.xml file.
Sample is as shown below:
Step 5
Thats is the end of Ehcache configuration.
Comments
Post a Comment