新增缓存监控功能

This commit is contained in:
RuoYi
2020-11-23 10:18:58 +08:00
parent 784cc3a10f
commit 30850c1fdf
9 changed files with 406 additions and 10 deletions

View File

@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.shiro.realm.UserRealm;
@ -175,6 +176,7 @@ public class ShiroConfig
public UserRealm userRealm(EhCacheManager cacheManager)
{
UserRealm userRealm = new UserRealm();
userRealm.setAuthorizationCacheName(Constants.SYS_AUTH_CACHE);
userRealm.setCacheManager(cacheManager);
return userRealm;
}

View File

@ -1,5 +1,7 @@
package com.ruoyi.framework.shiro.session;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.shiro.session.mgt.SimpleSession;
import com.ruoyi.common.enums.OnlineStatus;
@ -145,4 +147,19 @@ public class OnlineSession extends SimpleSession
{
return super.removeAttribute(key);
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("userId", getUserId())
.append("loginName", getLoginName())
.append("deptName", getDeptName())
.append("avatar", getAvatar())
.append("host", getHost())
.append("browser", getBrowser())
.append("os", getOs())
.append("status", getStatus())
.append("attributeChanged", isAttributeChanged())
.toString();
}
}

View File

@ -0,0 +1,83 @@
package com.ruoyi.framework.web.service;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.CacheUtils;
/**
* 缓存操作处理
*
* @author ruoyi
*/
@Service
public class CacheService
{
/**
* 获取所有缓存名称
*
* @return 缓存列表
*/
public String[] getCacheNames()
{
String[] cacheNames = CacheUtils.getCacheNames();
return ArrayUtils.removeElement(cacheNames, Constants.SYS_AUTH_CACHE);
}
/**
* 根据缓存名称获取所有键名
*
* @param cacheName 缓存名称
* @return 键名列表
*/
public Set<String> getCacheKeys(String cacheName)
{
return CacheUtils.getCache(cacheName).keys();
}
/**
* 根据缓存名称和键名获取内容值
*
* @param cacheName 缓存名称
* @param cacheKey 键名
* @return 键值
*/
public Object getCacheValue(String cacheName, String cacheKey)
{
return CacheUtils.get(cacheName, cacheKey);
}
/**
* 根据名称删除缓存信息
*
* @param cacheName 缓存名称
*/
public void clearCacheName(String cacheName)
{
CacheUtils.removeAll(cacheName);
}
/**
* 根据名称和键名删除缓存信息
*
* @param cacheName 缓存名称
* @param cacheKey 键名
*/
public void clearCacheKey(String cacheName, String cacheKey)
{
CacheUtils.remove(cacheName, cacheKey);
}
/**
* 清理所有缓存
*/
public void clearAll()
{
String[] cacheNames = getCacheNames();
for (String cacheName : cacheNames)
{
CacheUtils.removeAll(cacheName);
}
}
}