- userRealm=com.shiro.realm.UserRealm
- userRealm.credentialsMatcher=$credentialsMatcher
- userRealm.cachingEnabled=true
- userRealm.authenticationCachingEnabled=true
- userRealm.authenticationCacheName=authenticationCache
- userRealm.authorizationCachingEnabled=true
- userRealm.authorizationCacheName=authorizationCache
- securityManager.realms=$userRealm
- cacheManager=org.apache.shiro.cache.ehcache.EhCacheManager
- cacheManager.cacheManagerConfigFile=classpath:shiro-ehcache.xml
- 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就可以在这里配置
总结
- userRealm.cachingEnabled=true
- userRealm.authenticationCachingEnabled=true
- userRealm.authorizationCachingEnabled=true
可见 开启缓存 为true 关闭为false (默认值都为false)
默认关闭即可 ,以上三者都为false