# EhCache

notes for spring boot 1.X + EhCache 3.0  Spring 4

1. create CacheConfig.jave  for the annotation @EnableCaching, @Configuration
2. spring-bootstrap.xml add xmlns:cache to beans. add \<cache:annotation-driven /> for creating beans.
3. application.properities add one attribute spring.cache.jcache.config=classpath:ehcache.xml
4. add ehcache.xml: in the xml, eg:

```markup
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
	xmlns='http://www.ehcache.org/v3' xmlns:jsr107='http://www.ehcache.org/v3/jsr107'>

	<service>
		<jsr107:defaults enable-statistics="true" />
	</service>
	<cache alias="vcmmCache">
		<expiry>
			<ttl unit="seconds">10</ttl>
		</expiry>
		<resources>
			<heap unit="entries">2000</heap>
			<offheap unit="MB">100</offheap>
		</resources>
	</cache>
	<cache alias="vcmmCacheMarket">
		<resources>
			<heap unit="entries">2000</heap>
			<offheap unit="MB">100</offheap>
		</resources>
	</cache>
</config>
```

\<resources> is needed for creating CacheManager, also \<key-type>, \<value-type> are not necessary.&#x20;

jsr107 works for Spring 4 not Spring 3.&#x20;

{% embed url="<https://www.ehcache.org/documentation/3.4/tiering.html>" %}

{% embed url="<https://www.ehcache.org/documentation/3.4/caching-concepts.html#storage-tiers>" %}
