Ehcache3配置方式与Ehcache2的配置方式区别很大!
缓存管理器只有全局状态下其他地方才能根据名称拿到缓存,也就是只有保证在同一个缓存管理器下才能拿到指定缓存
两种配置方式可同时使用
xml配置方式
<config xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns='http://www.ehcache.org/v3'
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd">
<!-- http://www.ehcache.org/documentation/3.8/xml.html -->
<!--指定缓存持久化目录-->
<persistence directory="${java.io.tmpdir}/ehcache-data"/>
<!-- 1、声明一个名为foo的Cache-->
<cache alias="foo">
<!--2、foo的键值对被声明为字符串类型,如果没有指明,默认是Object类型。-->
<key-type>java.lang.String</key-type>
<value-type>java.lang.String</value-type>
<resources>
<!--3、foo被声明在堆上保存多达2,000个条目。-->
<heap unit="entries