首页 > 编程语言 > 详细

springBoot缓存技术-整合Ehcache

时间:2019-12-09 17:06:09      阅读:106      评论:0      收藏:0      [点我收藏+]

 

 

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));

}

}

 

springBoot缓存技术-整合Ehcache

原文:https://www.cnblogs.com/lijojo6/p/12012013.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!