zoukankan      html  css  js  c++  java
  • springBoot缓存技术-整合Ehcache

    1 修改pom文件

    2 创建Ehcache的配置文件

    文件名:ehcache.xml

    位置:src/main/resources/ehcache.xml

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">

        <diskStore path="java.io.tmpdir"/>

      <!--defaultCache:echcache的默认缓存策略  -->

        <defaultCache

                maxElementsInMemory="10000"

                eternal="false"

                timeToIdleSeconds="120"

                timeToLiveSeconds="120"

                maxElementsOnDisk="10000000"

                diskExpiryThreadIntervalSeconds="120"

                memoryStoreEvictionPolicy="LRU">

            <persistence strategy="localTempSwap"/>

        </defaultCache>

        <!-- 自定义缓存策略 -->

        <cache name="users"

                maxElementsInMemory="10000"

                eternal="false"

                timeToIdleSeconds="120"

                timeToLiveSeconds="120"

                maxElementsOnDisk="10000000"

                diskExpiryThreadIntervalSeconds="120"

                memoryStoreEvictionPolicy="LRU">

            <persistence strategy="localTempSwap"/>

        </cache>

    </ehcache>

    3 修改application.properties文件

    spring.datasource.driverClassName=com.mysql.jdbc.Driver

    spring.datasource.url=jdbc:mysql://localhost:3306/ssm

    spring.datasource.username=root

    spring.datasource.password=root

    spring.datasource.type=com.alibaba.druid.pool.DruidDataSource

    spring.jpa.hibernate.ddl-auto=update

    spring.jpa.show-sql=true

    spring.cache.ehcache.cofnig=ehcache.xml

    4 修改启动类


    5 创建业务层

    6 修改实体类Users

     

    7 测试

    /**

     * UsersService测试

     *

     *

     */

    @RunWith(SpringJUnit4ClassRunner.class)

    @SpringBootTest(classes=App.class)

    public class UsersServiceTest {

    @Autowired

    private UsersService usersService;

    @Test

    public void testFindUserById(){

    //第一次查询

    System.out.println(this.usersService.findUserById(1));

    //第二次查询

    System.out.println(this.usersService.findUserById(1));

    }

    }

  • 相关阅读:
    修改spring boot 的banner
    创建oracle 数据库的时候 提示 “使用database control配置数据库时,要求在当前oracle主目录中配置监听程序”
    Spring Boot 中文乱码解决
    SharePoint 2013 安装图解
    Hadoop 数据安全方案 Apache Eagle
    通用财经数据传输与监控平台1.0(泛型,接口与基类,Sql,Ibatis,Awt,Swing)
    应用Druid监控SQL语句的执行情况
    监控和剖析数据库操作 -- P6Spy、SQL Profiler、IronTrack SQL 使用简介
    Jboss7集群配置说明
    JavaMelody监控SQL
  • 原文地址:https://www.cnblogs.com/lijojo6/p/12012013.html
Copyright © 2011-2022 走看看