SpringBoot项目实战--ehcache
来源:互联网 发布:applet java 编辑:程序博客网 时间:2024/05/16 11:37
1、在pom.xml文件中添加以下依赖:
<!-- 添加缓存支持 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <!-- 使用ehcache缓存方案 --> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> </dependency>2、添加ehcache.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="false"> <diskStore path="java.io.tmpdir"/> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU"/> <cache name="tagUserCache" maxElementsInMemory="30" eternal="false" timeToIdleSeconds="1800" overflowToDisk="true" memoryStoreEvictionPolicy="LRU"/></ehcache>3、声明配置bean:
@Configuration@EnableCachingpublic class CacheConfig { /** * ehcache 主要的管理器 * @param bean * @return */ @Bean public EhCacheCacheManager ehCacheCacheManager(EhCacheManagerFactoryBean bean){ return new EhCacheCacheManager(bean.getObject()); } @Bean public EhCacheManagerFactoryBean ehCacheManagerFactoryBean(){ EhCacheManagerFactoryBean factoryBean = new EhCacheManagerFactoryBean(); factoryBean.setConfigLocation(new ClassPathResource("ehcache.xml")); factoryBean.setShared(true); return factoryBean; }}4、缓存使用:
@Service@CacheConfig(cacheNames="tagCache")public class TagServiceImpl implements TagService<Tag> {}还可以在方法上采用注解进行b不同类型的各种缓存配置。
0 0
- SpringBoot项目实战--ehcache
- SpringBoot项目实战--thymeleaf
- SpringBoot项目实战--mybatis
- SpringBoot项目实战--RabbitMQ
- SpringBoot项目实战--Jetty
- springboot项目实战开篇
- springboot Ehcache
- SpringBoot项目实战--环境搭建
- ehcache实战
- SpringBoot项目实战--Servlet、Filter、拦截器
- SpringBoot创建maven多模块项目(实战)
- SpringBoot项目中整合dubbo/zookeeper实战
- SpringBoot实战_1 Spring项目搭建
- SpringBoot项目实战(7):Filter、Listener
- SpringBoot+Maven项目实战(2):集成SpringBoot
- SpringBoot 实战 (一) :如何创建SpringBoot项目 --入门篇
- SpringBoot+Maven项目实战(2):集成SpringBoot
- springboot+Rabit实战三:(springboot+rabbit 项目搭建)
- 安卓——实用ListView显示消息列表
- centos安装python2.7
- 北京天宇联科技有限责任公司—智慧新园区
- 借鉴rocketmq
- android arr使用
- SpringBoot项目实战--ehcache
- vb.net项目,系统无法找到指定的引用及引用不被识别
- Java数据类型和MySql数据类型对应表
- 编程里一些有趣的名词解释(语法糖、面包屑导航)
- 配置Android Studio识别成员变量的m前缀
- LVM详解
- 二级指针修改一级指针的值
- 智能硬件
- 我见过最好的理解JSX和组件的文章