ajax获取shiroehcache,Shiro – 使用EhCache缓存
在Shiro中加入缓存可以使权限相关操作尽可能快,避免频繁访问数据库获取权限信息,因为对于一个用户来说,其权限在短时间内基本是不会变化的。
在上一篇Shiro – 权限控制中,当用户访问”获取用户信息”、”新增用户”和”删除用户”的时候,后台输出了三次打印信息
这对数据库来说是没必要的消耗。接下来使用缓存来解决这个问题。
引入EhCache的相关依赖
org.apache.shiro
shiro-ehcache
1.3.2
org.springframework.boot
spring-boot-starter-cache
net.sf.ehcache
ehcache
org.apache.shiro
shiro-ehcache
1.3.2
org.springframework.boot
spring-boot-starter-cache
net.sf.ehcache
ehcache
添加EhCache的配置文件
在src/main/resource/..路径下新增一个Ehcache配置——shiro-ehcache.xml:
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120" />
name="passwordRetryCache"
maxEntriesLocalHeap="2000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="0"
overflowToDisk="false"
statistics="true" />
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120" />
name="passwordRetryCache"
maxEntriesLocalHeap="2000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="0"
overflowToDisk="false"
statistics="true" />
将缓存对象注入到SecurityManager中
@Bean
public EhCacheManager getEhCacheManager() {
EhCacheManager em = new EhCacheManager();
em.setCacheManagerConfigFile("classpath:config/shiro-ehcache.xml");
return em;
}
@Bean
public SecurityManager securityManager(){
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(shiroRealm());
securityManager.setRememberMeManager(rememberMeManager());
securityManager.setCacheManager(getEhCacheManager());
return securityManager;
}
@Bean
public EhCacheManager getEhCacheManager() {
EhCacheManager em = new EhCacheManager();
em.setCacheManagerConfigFile("classpath:config/shiro-ehcache.xml");
return em;
}
@Bean
public SecurityManager securityManager(){
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(shiroRealm());
securityManager.setRememberMeManager(rememberMeManager());
securityManager.setCacheManager(getEhCacheManager());
return securityManager;
}
配置完毕启动项目,分别访问访问”获取用户信息”、”新增用户”和”删除用户”,可发现后台只打印一次获取权限信息:
ajax获取shiroehcache,Shiro – 使用EhCache缓存相关推荐
- shiro教程:整合ehcache缓存
这个是在ssm的基础上再去整合shiro和ehcache的,整合ehcache主要是为了减少后台shiro拦截的次数,因为如果我们不使用缓存的话,后台shiro的认证和授权的拦截器就会反复的进行拦截, ...
- SpringBoot整合Shiro使用Ehcache等缓存无效问题
前言 整合有缓存.事务的spring boot项目一切正常. 在该项目上整合shiro安全框架,发现部分类的缓存Cache不能正常使用. 然后发现该类的注解基本失效,包括事务Transaction注解 ...
- shiro整合ehcache
shiro的缓存是被shiro的缓存管理器所管理的,即CacheManage,Shiro的用户认证是没有提供缓冲机制的,因为每次登陆一次查询一次数据库比对一下用户名密码,做缓存的必要几乎是没有的. 但 ...
- Shiro框架:缓存、session会话、自定义FormAuthenticationFilter、RemenberMe
上篇的地址:https://blog.csdn.net/a745233700/article/details/81350191 一.Shiro缓存--cacheManager: 针对上一篇授权的时候频 ...
- 学习Spring Boot:(十九)Shiro 中使用缓存
前言 在 shiro 中每次去拦截请求进行权限认证的时候,都会去数据库查询该用户的所有权限信息, 这个时候就是有一个问题了,因为用户的权限信息在短时间内是不可变的,每次查询出来的数据其实都是重复数据, ...
- 关于SpringBoot整合Shiro并入redis缓存
关于SpringBoot整合Shiro并入redis缓存 最近做一个小项目加入shiro权限框架, Shiro是Apache下的一个开源项目,提供了认证.授权.加密.会话管理,与spring Secu ...
- Shiro 会话管理 缓存管理
目录 一.会话管理 1.基础组件 1.1 SessionManager 1.2 SessionListener 1.3 SessionDao 1.4 会话验证 2.使用步骤: 实现SessionLis ...
- Spring Boot 2.x基础教程:使用EhCache缓存集群
点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 上一篇我们介绍了在Spring Boot中整合EhCac ...
- javaweb项目搭建ehcache缓存系统
转载自 javaweb项目搭建ehcache缓存系统 EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider,同时在项目开发中 ...
最新文章
- Java可以跨平台的原因
- linux闲话FHS标准下linux目录结构
- 统计gitlab代码行脚本_一点也不复杂, GitLab Webhook 自动部署代码
- 新挑战之打造一流能源新材计算平台 2018-10-10
- 增加 Eclipse color Theme
- cbitmap 从内存中加载jpg_[转载]windows照片查看器无法显示图片内存不足
- 量子纠缠在量子计算机中的作用,量子纠缠
- 2.42死锁的处理策略一预防死锁
- 在拦截器里放入参数 controller_干货|SpringMVC拦截器的使用详解
- 人工智能实验评价指标_人工智能实验报告.pdf
- Access 操作必须使用可更新查询
- itextpdf table使用
- 企业信息化建设(Enterprise Informationization Construction)
- 【Fltk】Fltk1.3.3+VS2015 编程
- matlab 平滑曲线连接_用MATLAB做数据拟合究竟有多直观
- linux 网络速度非常慢,Linux认证:解决ubuntu8.10上网速度慢的问题
- 如何使用SPSS进行两因素重复测量的方差分析
- 部署超级账本fabric区块可视化浏览器
- 2023年,前端开发就业前景好吗?
- vue-aMap高德地图的应用(添加覆盖物点坐标、自定义图标、添加信息窗体信息等)
热门文章
- 用户注册的mysql代码_用户的注册登陆流程及代码实现
- mfc判断文件是否被读写_迅为干货|标准io之一个字符的读写函数
- 人机协作机器人发展趋势_移动机器人:人机协作是未来的发展趋势
- C++11向线程函数传递参数
- 中国石油计算机第二次在线作业,中国石油大学(北京)计算机应用基础第二次在线作业1教程.docx...
- linux进程通信ips,Cisco IPS 分析引擎拒绝服务漏洞(CVE-2014-0718)
- 双层json报文样例_json报文解析
- iOS重绘机制drawRect
- GitLab - Ubuntu18搭建GitLab仓库服务器(转)
- bzoj 3033 太鼓达人——欧拉图搜索