spring boot整合ehcache缓存框架( 二 )


                return sb.toString();
            }
        };
    }

spring boot整合ehcache缓存框架



3在resources目次下添加ehcache.xml设置装备摆设文件 , spring boot会默认读取类根路径下ehcache.xml设置装备摆设文件 , 添加了一个名为users的缓存空间,代码如下
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
         updateCheck="false">
    <defaultCache
            eternal="false"
            maxElementsInMemory="1000"
            overflowToDisk="false"
            diskPersistent="false"
            timeToIdleSeconds="0"
            timeToLiveSeconds="600"
            memoryStoreEvictionPolicy="LRU"/>
    <cache
            name="users"
            eternal="false"
            maxElementsInMemory="100"
            overflowToDisk="false"
            diskPersistent="false"
            timeToIdleSeconds="0"
            timeToLiveSeconds="300"
            memoryStoreEvictionPolicy="LRU"/>
</ehcache>   

spring boot整合ehcache缓存框架



4添加一个User实体类 , 用于缓存测试 , 代码如下
public class User implements Serializable {
    private String id;
    private String name;
    public User(String id, String name) {
        this.id = id;
        this.name = name;
    }
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
【spring boot整合ehcache缓存框架】        this.name = name;
    }
    @Override
    public String toString() {

猜你喜欢