Maven dependency for Spring with caching
If you are using Maven as a build tool, ensure that you add the ehcache dependency in the pom.xml
file. Below is the Maven dependency for using cache with spring's caching framework:
<groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <version>2.7.4</version> </dependency>
Declarative configuration of ehcache
In the following section, we can see how we can configure the cache storage declaratively. The ecache.xml
file is as follows:
<ehcache xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true" maxBytesLocalHeap="150M" > <diskStore path="java.io.tmpdir"/> <cache name="searchResults" maxBytesLocalHeap="100M" eternal="false" timeToIdleSeconds="300" overflowToDisk="true" maxElementsOnDisk="1000" memoryStoreEvictionPolicy="LRU"/> <cache...