验证码跟ehcash整合

简介: 基于spring做验证码跟chcash整合,初步的源码分析,关注点是怎么让chcash来缓存验证码,而不在于验证码的生成。

1.所有配置文件如下:

`

    <bean class="com.mocent.shiro.captcha.DreamCaptcha">
    <property name="cacheManager" ref="shiroSpringCacheManager"/>
        <!-- 复用半小时缓存 -->
        <property name="cacheName" value="halfHour"/>
    </bean>

`
`

    <bean id="shiroSpringCacheManager" class="com.mocent.shiro.cash.ShiroSpringCacheManager">
        <property name="cacheManager" ref="cacheManager"/>
</bean>

`
`
3.

    <property name="cacheManager" ref="ehcacheManager"/>
    <property name="transactionAware" value="true"/>
</bean>

`
`

<bean id="ehcacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:cash/ehcache.xml"/>
</bean>`

`5.

    <cache name="halfHour" 
    maxElementsInMemory="10000"
    maxElementsOnDisk="100000" 
    eternal="false" 
    timeToIdleSeconds="1800"
    timeToLiveSeconds="1800"
    overflowToDisk="false"
    diskPersistent="false" />

`

2. 类图

image

image
这个bean将要被IOC实例化,通过get set的方式传参数进去,被赋值的属性是cacheManager和cacheName。cacheName是直接赋值为halfHour字符串,而cacheManager属性来自
image
ShiroSpringCacheManager的属性以及方法如下
image
也是使用get set的方式设置值被设值的属性是cacheManager,cacheManager来自
image
image
经过一系列的传递后发现最终的验证码的缓存管理类是EhCacheCacheManager,它实现了org.springframework.cache.CacheManager接口可以被com.mocent.shiro.captcha.DreamCaptcha使用
继续往下看
image
org.springframework.cache.CacheManager的cacheManager参数是来自org.springframework.cache.ehcache.EhCacheManagerFactoryBean他是EhCacheCacheManager的工厂类,生成EhCacheCacheManager的配置文件是
cash/ehcache.xml里面有一个名为halfHour的缓存配置
image
这也是验证码生成类com.mocent.shiro.captcha.DreamCaptcha的另外一个属性的来源

目录
相关文章
|
监控 算法 数据库
深度解读Facebook刚开源的beringei时序数据库
Facebook最近开源了beringei时序数据库,其是用来解决其内部监控数据存储和查询需求的数据库,特点是读写速度快。beringei在压缩算法上有哪些独到之处?本文中阿里云数据库高级专家叶翔将为大家深度解读。
19683 0
sql面试50题------(1-10)
这篇文章提供了SQL面试中的前10个问题及其解决方案,包括查询特定条件下的学生信息、教师信息和课程成绩等。
sql面试50题------(1-10)
|
设计模式 API Python
Python Web:Django、Flask和FastAPI框架对比
Python Web:Django、Flask和FastAPI框架对比
537 0
|
Python
[pandas]从多个文件中构建dataframe
[pandas]从多个文件中构建dataframe
128 0
|
存储 Linux 数据安全/隐私保护
Linux用户和用户组,useradd test2 -g itcast -d /home/test222 设置分组和存放路径
Linux用户和用户组,useradd test2 -g itcast -d /home/test222 设置分组和存放路径
|
Java 数据库连接 Spring
【Spring事务底层实现原理】
【Spring事务底层实现原理】
257 0
|
监控 网络协议 Java
【网络篇】第十篇——线程池版的TCP网络程序
【网络篇】第十篇——线程池版的TCP网络程序
【网络篇】第十篇——线程池版的TCP网络程序
|
机器学习/深度学习 算法 搜索推荐
<<算法很美>>——(二)详解递归思想
<<算法很美>>——(二)详解递归思想
<<算法很美>>——(二)详解递归思想
|
前端开发
react项目导出数据doc格式及其他格式方法
react项目导出数据doc格式及其他格式方法
react项目导出数据doc格式及其他格式方法
|
算法 前端开发 程序员
「LeetCode」JavaScript-快速排序⚡️
「LeetCode」JavaScript-快速排序⚡️
194 0
「LeetCode」JavaScript-快速排序⚡️