Use shiro, ShiroConfig defined in the instance of the object securityManager:
@Bean
public SecurityManager securityManager(MyShiroRealm myShiroRealm, RedissonWebSessionManager redissonWebSessionManager, RedissonShiroCacheManager redissonShiroCacheManager) {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
// 自定义缓存实现 使用redis
securityManager.setCacheManager(redissonShiroCacheManager);
return securityManager;
}
RedissonShiroCacheManager which is redis custom implement caching, redissonShiroCacheManager acquired cache objects getCache. Process describes cache data access target:
RedissonShiroCache <K, V> the implements the Cache <K, V>
@Override
public V get(K key) throws CacheException {
Object value = (RedissonShiroCache)this.map.get(key); //获取缓存
return fromStoreValue(value);
}
this.map.get (key) acquires cache, wherein the map type is RMap <K, Object> map, when calling get () method will be called the implementation class RMap RedissonMap <K, V>:
public V get(Object key) {
return this.get(this.getAsync(key));
}
The following method is put, get the same manner as the above process:
RedissonShiroCache <K, V> the implements the Cache <K, V>
@Override
public V put(K key, V value) throws CacheException {
Object previous = this.map.put(key, val, config.getTTL(), TimeUnit.MILLISECONDS,
config.getMaxIdleTime(), TimeUnit.MILLISECONDS);
return fromStoreValue(previous);
}
RedissonMap<K, V>
public V put(K key, V value) {
return this.get(this.putAsync(key, value));
}