shiro Realm 缓存默认值

  1. userRealm=com.shiro.realm.UserRealm  
  2. userRealm.credentialsMatcher=$credentialsMatcher  
  3. userRealm.cachingEnabled=true  
  4. userRealm.authenticationCachingEnabled=true  
  5. userRealm.authenticationCacheName=authenticationCache  
  6. userRealm.authorizationCachingEnabled=true  
  7. userRealm.authorizationCacheName=authorizationCache  
  8. securityManager.realms=$userRealm  
  9.   
  10. cacheManager=org.apache.shiro.cache.ehcache.EhCacheManager  
  11. cacheManager.cacheManagerConfigFile=classpath:shiro-ehcache.xml  
  12. securityManager.cacheManager=$cacheManager   

userRealm.cachingEnabled:启用缓存,默认false;

userRealm.authenticationCachingEnabled:启用身份验证缓存,即缓存AuthenticationInfo信息,默认false;

userRealm.authenticationCacheName:缓存AuthenticationInfo信息的缓存名称;

userRealm. authorizationCachingEnabled:启用授权缓存,即缓存AuthorizationInfo信息,默认false;

userRealm. authorizationCacheName:缓存AuthorizationInfo信息的缓存名称;

cacheManager:缓存管理器,此处使用EhCacheManager,

 

 

CacheManage(缓存管理)
   Realm中使用缓存
   
   在Realm中有2个使用缓存的地方
   1、认证缓存
   首先判断getAuthenticationCache()是否为空,如果未设置则判断authenticationCachingEnabled=true&&cachingEnabled=true如果都为true
   则通过设置的cacheManager中取出name=authenticationCacheName的缓存
   也就是说要想使用认证缓存,则在Realm中有2种方式设置
   一种是通过设置cacheManager
      然后设置 authenticationCacheName(认证缓存名)authenticationCachingEnabled=true、cachingEnabled=true
   或者直接设置
   public void setAuthenticationCache(Cache authenticationCache)
     
   2、授权缓存
   首先判断getAuthorizationCache()如果未设置则判断authorizationCachingEnabled=true&&cachingEnabled=true如果都为true
   则通过设置的cacheManager中取出name=authorizationCacheName的缓存
   也就是说要想使用授权缓存,则在Realm中有2种方式设置
   一种是通过设置cacheManager
      然后设置 authorizationCacheName(授权缓存名)、authorizationCachingEnabled=true、cachingEnabled=true
   或者直接设置
   public void setAuthorizationCache(Cache authorizationCache)
   
  上面有很多变量值需要设置,Realm默认情况下
     authorizationCachingEnabled=true(是否可授权缓存)
     authenticationCachingEnabled=false(是否可认证缓存)
     cachingEnabled=true(是否可缓存)
  目前认证缓存功能使用不了,当缓存时序列化时对应的对象无法序列化;而且一般也不要使用认证缓存,避免修改密码无法及时生效
  授权缓存可以在session期间有效,session过期后重新取授权
  
  SessionManager中使用缓存
  在这里使用缓存的目的主要是管理系统session的缓存,比如系统如果想使用memcached来管理session就可以在这里配置

 

 

总结

 

  1. userRealm.cachingEnabled=true  
  2. userRealm.authenticationCachingEnabled=true  
  3. userRealm.authorizationCachingEnabled=true  

 

 

 

可见 开启缓存 为true 关闭为false (默认值都为false)

默认关闭即可 ,以上三者都为false

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值