借助Shiro的缓存管理器将数据缓存起来。
1
内置缓存管理器:org.apache.shiro.cache.MemoryConstrainedCacheManager
2
Ehcache管理器:org.apache.shiro.cache.ehcache.EhCacheManager
3
redis缓存管理器:org.crazycake.shiro.RedisCacheManager
<!‐‐配置安全管理器‐‐>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <property name="realm" ref="authRealm"/><!‐‐ 引用自定义的realm ‐‐>
<!‐‐注入缓存管理器:缓存用户的权限信息‐‐>
<property name="cacheManager" ref="cacheManger"></property>
</bean>
<!‐‐创建内置的内存缓存管理器 <bean id="cacheManger" class="org.apache.shiro.cache.MemoryConstrainedCacheManager"></bean> ‐‐>
<!‐‐创建ehcache的缓存管理器:基于文件的缓存管理 <bean id="cacheManger" class="org.apache.shiro.cache.ehcache.EhCacheManager">
注入ehcache的配置文件
<property name="cacheManagerConfigFile" value="classpath:config/ehcache‐shiro.xml"> </property>
</bean>‐‐>
<!‐‐基于redis的缓存管理器‐‐>
<!‐‐1.redis配置‐‐>
<bean id="redisManager" class="org.crazycake.shiro.RedisManager">
<property name="host" value="127.0.0.1:6379"></property>
</bean>
<!‐‐2.创建redis的缓存管理器‐‐>
<bean id="cacheManger" class="org.crazycake.shiro.RedisCacheManager"> <property name="redisManager" ref="redisManager"></property>
</bean>