Ehcache 学习笔记(一) 搭建开发环境

 

 Ehcache 官方下载地址 http://ehcache.org/ 下载:ehcache-2.6.6-distribution.tar.gz  免费下载 但是下载需要注册

 1 将解压开lib文件夹下面的jar文件导入到我们的项目中去,怎么导入在这里就不演示了。

 2 拷贝ehcache.xml 到项目的src目录下面

 3 编写一个基本的配置 XML 配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
         updateCheck="true" monitoring="autodetect"
         dynamicConfig="true">
         
    <cache
        name="simpleCache" //缓存的名字,在后面会用到
        maxElementsInMemory="10000" //缓存中存入元素的最大数量
        eternal="false" //缓存中的元素是否永远存活不过期
        timeToIdleSeconds="120" //这个配置是缓存多久不被访问即失效,如果被访问了以后又重新开始计时
        timeToLiveSeconds="120" //缓存中元素的生命周期,单位(秒)
>
    </cache>
</ehcache>

 4:  编写测试对象

package com.aop.demo;

public class User {

    private int id;
    
    private String name;

    public User(int id, String name) {
        super();
        this.id = id;
        this.name = name;
    }
    
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-10
  • 2021-12-01
  • 2022-12-23
  • 2021-07-02
  • 2021-10-14
  • 2021-10-31
猜你喜欢
  • 2021-09-30
  • 2021-06-06
  • 2022-12-23
  • 2021-10-16
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案