Ehcache is easy and very powerful object caching system. In this tutorial I'm going to show how to start using the ehcache.First step is to download the distribution. From the archive you need the ehcache-core-2.3.1.jar - jar file contains everything that is need to use ehcache.
ehcache.xsd - schema for the ehcache configuration file.
First you need to create configuration file ehcache.xml.ehcache.xml <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true" monitoring="autodetect"
dynamicConfig="true"> <!-- Specify cache storage location -->
<diskStore path="/tmp/jprofessional/cache"/>
<cache name="test"
maxElementsInMemory="50"
maxElementsOnDisk="5000"
eternal="false"
overflowToDisk="true"
diskSpoolBufferSizeMB="20"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off"
/></ehcache>Configuration defines storage directory and cache with name "test". Let's define the object that we are going to put into cache:package com.jprofessional.ehcache;public class TestBean {
private String name;
private Integer id; public TestBean() {
super();
} public void setName(String aName) {
name = aName;
} public String getName() {
return name;
} public void setId(Integer aId) {
id = aId;
} public Integer getId() {Read more: JP Professional
ehcache.xsd - schema for the ehcache configuration file.
First you need to create configuration file ehcache.xml.ehcache.xml <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true" monitoring="autodetect"
dynamicConfig="true"> <!-- Specify cache storage location -->
<diskStore path="/tmp/jprofessional/cache"/>
<cache name="test"
maxElementsInMemory="50"
maxElementsOnDisk="5000"
eternal="false"
overflowToDisk="true"
diskSpoolBufferSizeMB="20"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off"
/></ehcache>Configuration defines storage directory and cache with name "test". Let's define the object that we are going to put into cache:package com.jprofessional.ehcache;public class TestBean {
private String name;
private Integer id; public TestBean() {
super();
} public void setName(String aName) {
name = aName;
} public String getName() {
return name;
} public void setId(Integer aId) {
id = aId;
} public Integer getId() {Read more: JP Professional
0 comments:
Post a Comment