04 shiro的缓存管理

时间:2020-03-18 22:34:07   收藏:0   阅读:70

前面我们看了shiro与spring的整合,接下来我们来了解一下shiro的缓存管理。

1、前提约束

    <bean id="userRealm" class="net.wanho.security.MyRealm">
        <property name="authenticationCachingEnabled" value="true"></property>
        <property name="authorizationCachingEnabled" value="true"></property>
    </bean>
    <!--缓存管理-->
    <bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager"/>

    <!--安全管理器-->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="realm" ref="userRealm"/>
        <property name="cacheManager" ref="cacheManager"></property>
    </bean>

到这里,就可以看到缓存的效果了,用户不会每次都去查数据库;但要注意的一点是,一旦权限有所改变,务必要让缓存失效,让授权逻辑再去查询数据库,保证数据一致性。
以上就是shiro中的缓存管理。

原文:https://www.cnblogs.com/alichengxuyuan/p/12519994.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!