网站首页 > 博客文章 正文
基于redis和ehcache的两级缓存组件,支持spring-boot,使用方便,有管理页面。
功能概述
- 统一注解支持
- 可以设置缓存定时自动更新时间
- 可以缓存预热
- 可以设置缓存依赖消除
- 可以添加监听,使用实现命中率、读/写耗时等
spring boot
1. application.peroperties
uncode.cache.redisClusterAddress=127.0.0.1:7000;127.0.0.1:7001;127.0.0.1:7002;127.0.0.1:7003;127.0.0.1:7004;127.0.0.1:7005 uncode.cache.redisPoolMaxIdle= uncode.cache.redisPoolMinIdle = uncode.cache.redisPoolMaxTotal= uncode.cache.redisPoolMaxWaitMillis= uncode.cache.redisClusterTimeout= uncode.cache.redisClusterMaxRedirections= uncode.cache.redisClusterPassword uncode.cache.scanPackage=cn.uncode.cache uncode.cache.useLocal=true uncode.cache.openCacheLog=false uncode.cache.storeRegion=uncode-cache-demo
2. spring boot启动类
@SpringBootApplication @EnableAspectJAutoProxy public class Application { public static void main(String[] agrs){ SpringApplication.run(Application.class,agrs); } }
spring配置
<bean id="propertyConfigurer" class="cn.uncode.util.config.UncodePropertyPlaceholderConfigurer"> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> <list> <value>classpath:config.properties</value> </list> </property> </bean> <!-- 设置代理 --> <aop:aspectj-autoproxy proxy-target-class="true"/> <!-- 配置缓存池 --> <bean id="jedisCluster" class="com.ksudi.proxycache.store.redis.JedisClusterFactory" /> <bean id="cache" class="com.ksudi.proxycache.store.redis.RedisStore"> <property name="jedisCluster" ref="jedisCluster" /> </bean> <!-- 配置缓存代理管理器 --> <bean id="proxyCacheManager" class="com.ksudi.proxycache.ConfigCacheManager" init-method="init"> <!-- 注解的扫描路径 --> <property name="scanPackage" value="com.ksudi.star.service"></property> <property name="cache" ref="cache" /> </bean> <!-- 配置aop缓存处理器 --> <bean class="com.ksudi.proxycache.framework.aop.handle.CacheManagerHandle"> <property name="cacheManager" ref="proxyCacheManager" /> </bean>
核心注解
@Cache( preload = true,//是否需要缓存预热,会在系统启动时自已加载,支持特殊场景 preloadParameters = {"param1", "param2"},//加载方法参数,目前只支持String expiredTime = 60,//缓存有效时间,单位秒 cleanTimeExpressions = "0 15 10 ? * *",//缓存定时清除时间表达式,如:每天10点15分触发 cacheCleans={//依赖清除bean定义,当该方法被调用时清除当前缓存,可定义多个 @CacheClean( beanName="couriersService6",//bean名称 methodName="updateCourierPwd"//方法名称 ) } ) public User getUserById(){...}
工具类
可以直接使用cn.uncode.cache.CacheUtils工具类。
管理页面
以spring-boot方式启动cn.uncode.cache.springboot.Application类,访问http://localhost:8808/static/index.html
猜你喜欢
- 2024-09-26 melon-idfactory主键工厂,提供ID生成服务,保证ID的唯一性。
- 2024-09-26 Spring Boot中的Properties(springboot property)
- 2024-09-26 Spring-基础笔记(一)(spring详细教程)
- 2024-09-26 带你读源码2——Spring源码分析之容器的刷新 - refresh()
- 2024-09-26 super-diamond 结合springboot的使用经验(用过的都说好)
- 2024-09-26 还在为数据同步而苦恼吗?手把手教你实现canal数据同步(一)
- 2024-09-26 源码分析:Spring是如何获取容器中的Bean?
- 2024-09-26 五种方式让你在java中读取properties文件内容
- 2024-09-26 图表显示日志离线信息(图表显示日志离线信息什么意思)
- 2024-09-26 Java程序员 必须掌握的 20+ 种 Spring 常用注解
你 发表评论:
欢迎- 最近发表
-
- 给3D Slicer添加Python第三方插件库
- Python自动化——pytest常用插件详解
- Pycharm下安装MicroPython Tools插件(ESP32开发板)
- IntelliJ IDEA 2025.1.3 发布(idea 2020)
- IDEA+Continue插件+DeepSeek:开发者效率飙升的「三体组合」!
- Cursor:提升Python开发效率的必备IDE及插件安装指南
- 日本旅行时想借厕所、买香烟怎么办?便利商店里能解决大问题!
- 11天!日本史上最长黄金周来了!旅游万金句总结!
- 北川景子&DAIGO缘定1.11 召开记者会宣布结婚
- PIKO‘PPAP’ 洗脑歌登上美国告示牌
- 标签列表
-
- ifneq (61)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)