在springcloud中我们可以使用spring-boot-starter-data-redis已经为我们处理好分布式缓存,但是我们还是不满足于只存在于网络中传输的缓存,我们现在来扩展成本地加Redis双级缓存,这样就可以减少网络传输带来的传输效率。
以下是针对已经整理好的项目进行直接使用
打包安装项目 springcloud-twocache
git clone https://github.com/dounine/spring-cloud.gitcd spring-cloudgradle install -xtest
在项目中引用
build.gradle
dependencies { compile('com.dounine.twocache:springcloud-twocache:0.0.1-SNAPSHOT')}
在application.yml添加如下代码
spring: redis: host: localhost port: 6379twocache: enable: true redis: topic: 项目名
java代码中使用(与spring cache使用缓存一样)
@Cacheable(cacheNames = "user