优化缓存系统模式

v1.4.1
Parker 5 years ago
parent 724ceb5109
commit ada54b6b97

@ -15,7 +15,6 @@
*/
package org.opsli.common.annotation.hotdata;
import org.opsli.common.constants.CacheConstants;
import java.lang.annotation.*;
@ -41,7 +40,5 @@ import java.lang.annotation.*;
@Documented
public @interface HotDataDel {
/** 缓存源名字 */
String name() default CacheConstants.HOT_DATA;
}

@ -15,7 +15,6 @@
*/
package org.opsli.common.annotation.hotdata;
import org.opsli.common.constants.CacheConstants;
import java.lang.annotation.*;
@ -41,7 +40,5 @@ import java.lang.annotation.*;
@Documented
public @interface HotDataPut {
/** 缓存源名字 */
String name() default CacheConstants.HOT_DATA;
}

@ -26,12 +26,10 @@ public interface CacheConstants {
String PREFIX_NAME = "opsli";
/** 热点数据 */
String HOT_DATA = "hotData";
/** Ehcache 缓存存放空间 */
String EHCACHE_SPACE = "timed";
/** 永久常量 */
String EDEN_DATA = "edenData";
/** 热数据前缀 */
String HOT_DATA_PREFIX = "hot_data";
/** 永久Hash常量 */
String EDEN_HASH_DATA = "edenHashData";
}

@ -0,0 +1,44 @@
package org.opsli.common.enums;
/**
*
*
* @author Parker
*/
public enum CacheType {
/** 缓存类型 */
TIMED("timed", "时控数据"),
EDEN("eden", "永久数据"),
EDEN_HASH("edenhash", "永久Hash数据")
;
private final String name;
private final String desc;
public static CacheType getCacheType(String cacheType) {
CacheType[] var1 = values();
for (CacheType type : var1) {
if (type.name.equalsIgnoreCase(cacheType)) {
return type;
}
}
return null;
}
public String getName() {
return this.name;
}
public String getDesc() {
return this.desc;
}
// =================
CacheType(final String name, final String desc) {
this.name = name;
this.desc = desc;
}
}

@ -40,7 +40,7 @@ public class WafConfig {
private GlobalProperties globalProperties;
@Bean
@ConditionalOnProperty(prefix = GlobalProperties.PREFIX +".waf", name = "enable", havingValue = "true", matchIfMissing = false)
@ConditionalOnProperty(prefix = GlobalProperties.PROP_PREFIX +".waf", name = "enable", havingValue = "true", matchIfMissing = false)
public FilterRegistrationBean<WafFilter> wafFilterRegistration() {
WafFilter wafFilter = new WafFilter();
wafFilter.setUrlExclusion(globalProperties.getWaf().getUrlExclusion());

@ -25,11 +25,13 @@ import org.springframework.stereotype.Component;
* @author parker
*/
@Component
@ConfigurationProperties(prefix = "server.servlet.api.path")
@ConfigurationProperties(prefix = ApiPathProperties.PROP_PREFIX)
@Data
@EqualsAndHashCode(callSuper = false)
public class ApiPathProperties {
public static final String PROP_PREFIX = "server.servlet.api.path";
/** 专门针对 Controller层接口路径前缀全局配置 */
private String globalPrefix;

@ -0,0 +1,38 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.autoconfigure.properties;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
*
* @author parker
*/
@Component
@ConfigurationProperties(prefix = CacheProperties.PROP_PREFIX)
@Data
@EqualsAndHashCode(callSuper = false)
public class CacheProperties {
public static final String PROP_PREFIX = "spring.cache-conf";
/** 缓存前缀 */
private String prefix;
}

@ -14,12 +14,12 @@ import java.util.Set;
* @date 2021-01-31 5:52
**/
@Configuration
@ConfigurationProperties(prefix = GlobalProperties.PREFIX)
@ConfigurationProperties(prefix = GlobalProperties.PROP_PREFIX)
@Data
@EqualsAndHashCode(callSuper = false)
public class GlobalProperties {
public static final String PREFIX = "opsli";
public static final String PROP_PREFIX = "opsli";
/** 系统名称 */
private String systemName;

@ -119,7 +119,7 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
// 如果开启缓存 先从缓存读
if(hotDataFlag){
model = WrapperUtil.transformInstance(
CacheUtil.get(id, entityClazz),modelClazz);
CacheUtil.getTimed(entityClazz, id), modelClazz);
if(model != null){
return model;
}
@ -147,7 +147,7 @@ public abstract class BaseRestController <T extends BaseEntity, E extends ApiWra
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
model = WrapperUtil.transformInstance(
CacheUtil.get(id, entityClazz),modelClazz);
CacheUtil.getTimed(entityClazz, id),modelClazz);
if(model != null){
return model;
}

@ -36,15 +36,12 @@ public class CacheDataEntity {
/** key */
private String key;
/** 数据类型 */
private PushSubType type;
/** 缓存名称 */
private String cacheName;
public static void main(String[] args) {
CacheDataEntity ret = new CacheDataEntity("123", PushSubType.EDEN_DATA, "12aaaa");
CacheDataEntity ret = new CacheDataEntity("123", "12aaaa");
System.out.println(ToStringBuilder.reflectionToString(ret));
}
}

@ -22,7 +22,7 @@ package org.opsli.core.cache.pushsub.enums;
* @CreateTime: 2020-09-16 22:28
* @Description:
*/
public enum CacheType {
public enum CacheHandleType {
/** 更新 */
UPDATE,

@ -59,6 +59,8 @@ public enum MsgArgsType {
/** 缓存数据Key */
CACHE_DATA_KEY,
/** 缓存数据Key */
CACHE_DATA_NAME,
/** 缓存数据Value */
CACHE_DATA_VALUE,
/** 缓存数据Type */

@ -42,9 +42,6 @@ public enum PushSubType {
/** 热点数据 */
HOT_DATA,
/** 永久数据 */
EDEN_DATA,
;

@ -22,15 +22,15 @@ import lombok.extern.slf4j.Slf4j;
import org.opsli.api.wrapper.system.dict.DictWrapper;
import org.opsli.common.constants.CacheConstants;
import org.opsli.common.constants.DictConstants;
import org.opsli.common.enums.CacheType;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.cache.pushsub.enums.CacheType;
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
import org.opsli.core.cache.pushsub.enums.DictModelType;
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
import org.opsli.core.cache.pushsub.enums.PushSubType;
import org.opsli.plugins.cache.EhCachePlugin;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collection;
import java.util.List;
/**
@ -54,7 +54,7 @@ public class DictHandler implements RedisPushSubHandler{
@Override
public void handler(JSONObject msgJson) {
DictModelType dictModelType = DictModelType.valueOf((String) msgJson.get(MsgArgsType.DICT_MODEL_TYPE.toString()));
CacheType type = CacheType.valueOf((String) msgJson.get(MsgArgsType.DICT_TYPE.toString()));
CacheHandleType type = CacheHandleType.valueOf((String) msgJson.get(MsgArgsType.DICT_TYPE.toString()));
if(DictModelType.COLLECTION == dictModelType){
Object dictListObj = msgJson.get(MsgArgsType.DICT_MODELS.toString());
@ -81,29 +81,29 @@ public class DictHandler implements RedisPushSubHandler{
* @param dictWrapperModel
* @param type
*/
private void handler(DictWrapper dictWrapperModel, CacheType type){
private void handler(DictWrapper dictWrapperModel, CacheHandleType type){
// 解析 key
String ehKeyByName = CacheUtil.handleKey(CacheConstants.EDEN_HASH_DATA,
DictConstants.CACHE_PREFIX_NAME + dictWrapperModel.getTypeCode() + ":" + dictWrapperModel.getDictName());
String ehKeyByValue = CacheUtil.handleKey(CacheConstants.EDEN_HASH_DATA,
DictConstants.CACHE_PREFIX_VALUE + dictWrapperModel.getTypeCode() + ":" + dictWrapperModel.getDictValue());
String ehKeyByName = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_NAME +
dictWrapperModel.getTypeCode() + ":" + dictWrapperModel.getDictName());
String ehKeyByValue = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_VALUE +
dictWrapperModel.getTypeCode() + ":" + dictWrapperModel.getDictValue());
// 缓存更新
if(CacheType.UPDATE == type){
ehCachePlugin.delete(CacheConstants.HOT_DATA, ehKeyByName);
ehCachePlugin.delete(CacheConstants.HOT_DATA, ehKeyByValue);
if(CacheHandleType.UPDATE == type){
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, ehKeyByName);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, ehKeyByValue);
// 统一转换为 JSONObject
String jsonStr = JSONObject.toJSONString(dictWrapperModel.getModel());
JSONObject value = JSONObject.parseObject(jsonStr);
ehCachePlugin.put(CacheConstants.HOT_DATA, ehKeyByName, value);
ehCachePlugin.put(CacheConstants.HOT_DATA, ehKeyByValue, value);
ehCachePlugin.put(CacheConstants.EHCACHE_SPACE, ehKeyByName, value);
ehCachePlugin.put(CacheConstants.EHCACHE_SPACE, ehKeyByValue, value);
}
// 缓存删除
else if(CacheType.DELETE == type){
ehCachePlugin.delete(CacheConstants.HOT_DATA, ehKeyByName);
ehCachePlugin.delete(CacheConstants.HOT_DATA, ehKeyByValue);
else if(CacheHandleType.DELETE == type){
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, ehKeyByName);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, ehKeyByValue);
}
}

@ -1,67 +0,0 @@
/**
* Copyright 2020 OPSLI https://www.opsli.com
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.opsli.core.cache.pushsub.handler;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.opsli.common.constants.CacheConstants;
import org.opsli.common.constants.DictConstants;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.cache.pushsub.enums.CacheType;
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
import org.opsli.core.cache.pushsub.enums.PushSubType;
import org.opsli.plugins.cache.EhCachePlugin;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @BelongsProject: opsli-boot
* @BelongsPackage: org.opsli.core.cache.pushsub.handler
* @Author: Parker
* @CreateTime: 2020-09-15 16:24
* @Description:
*/
@Slf4j
public class EdenDataHandler implements RedisPushSubHandler{
@Autowired
private EhCachePlugin ehCachePlugin;
@Override
public PushSubType getType() {
return PushSubType.EDEN_DATA;
}
@Override
public void handler(JSONObject msgJson) {
String key = (String) msgJson.get(MsgArgsType.CACHE_DATA_KEY.toString());
Object value = msgJson.get(MsgArgsType.CACHE_DATA_VALUE.toString());
CacheType type = CacheType.valueOf((String )msgJson.get(MsgArgsType.CACHE_DATA_TYPE.toString()));
// 解析 key
String handleKey = CacheUtil.handleKey(CacheConstants.EDEN_DATA,key);
// 缓存更新
if(CacheType.UPDATE == type){
ehCachePlugin.put(CacheConstants.HOT_DATA, handleKey, value);
}
// 缓存删除
else if(CacheType.DELETE == type){
ehCachePlugin.delete(CacheConstants.HOT_DATA, handleKey);
}
}
}

@ -18,8 +18,7 @@ package org.opsli.core.cache.pushsub.handler;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.opsli.common.constants.CacheConstants;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.cache.pushsub.enums.CacheType;
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
import org.opsli.core.cache.pushsub.enums.PushSubType;
import org.opsli.plugins.cache.EhCachePlugin;
@ -46,18 +45,16 @@ public class HotDataHandler implements RedisPushSubHandler{
@Override
public void handler(JSONObject msgJson) {
String key = (String) msgJson.get(MsgArgsType.CACHE_DATA_KEY.toString());
String cacheName = (String) msgJson.get(MsgArgsType.CACHE_DATA_NAME.toString());
Object value = msgJson.get(MsgArgsType.CACHE_DATA_VALUE.toString());
CacheType type = CacheType.valueOf((String )msgJson.get(MsgArgsType.CACHE_DATA_TYPE.toString()));
CacheHandleType type = CacheHandleType.valueOf((String )msgJson.get(MsgArgsType.CACHE_DATA_TYPE.toString()));
// 解析 key
String handleKey = CacheUtil.handleKey(CacheConstants.HOT_DATA, key);
if(CacheType.UPDATE == type){
ehCachePlugin.put(CacheConstants.HOT_DATA, handleKey, value);
if(CacheHandleType.UPDATE == type){
ehCachePlugin.put(CacheConstants.EHCACHE_SPACE, cacheName, value);
}
// 缓存删除
else if(CacheType.DELETE == type){
ehCachePlugin.delete(CacheConstants.HOT_DATA, handleKey);
else if(CacheHandleType.DELETE == type){
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheName);
}
}

@ -67,10 +67,10 @@ public class MenuHandler implements RedisPushSubHandler{
return;
}
String cacheKey = CacheUtil.handleKey(MenuUtil.PREFIX_CODE + menuCode);
// 先删除
ehCachePlugin.delete(CacheConstants.HOT_DATA, MenuUtil.PREFIX_CODE + menuCode);
// 清除空拦截
CacheUtil.delNilFlag(MenuUtil.PREFIX_CODE + menuCode);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
}

@ -22,7 +22,6 @@ import org.opsli.common.constants.CacheConstants;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
import org.opsli.core.cache.pushsub.enums.PushSubType;
import org.opsli.core.utils.MenuUtil;
import org.opsli.core.utils.OrgUtil;
import org.opsli.plugins.cache.EhCachePlugin;
import org.springframework.beans.factory.annotation.Autowired;
@ -68,10 +67,10 @@ public class OrgHandler implements RedisPushSubHandler{
return;
}
String cacheKey = CacheUtil.handleKey(OrgUtil.PREFIX_CODE + userId);
// 先删除
ehCachePlugin.delete(CacheConstants.HOT_DATA, OrgUtil.PREFIX_CODE + userId);
// 清除空拦截
CacheUtil.delNilFlag(OrgUtil.PREFIX_CODE + userId);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
}

@ -22,7 +22,6 @@ import org.opsli.common.constants.CacheConstants;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
import org.opsli.core.cache.pushsub.enums.PushSubType;
import org.opsli.core.utils.OrgUtil;
import org.opsli.core.utils.TenantUtil;
import org.opsli.plugins.cache.EhCachePlugin;
import org.springframework.beans.factory.annotation.Autowired;
@ -68,10 +67,10 @@ public class TenantHandler implements RedisPushSubHandler{
return;
}
String cacheKey = CacheUtil.handleKey(TenantUtil.PREFIX_CODE + tenantId);
// 先删除
ehCachePlugin.delete(CacheConstants.HOT_DATA, TenantUtil.PREFIX_CODE + tenantId);
// 清除空拦截
CacheUtil.delNilFlag(TenantUtil.PREFIX_CODE + tenantId);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
}

@ -88,12 +88,12 @@ public class UserHandler implements RedisPushSubHandler{
return;
}
String cacheKeyById = CacheUtil.handleKey(UserUtil.PREFIX_ID + userId);
String cacheKeyByName = CacheUtil.handleKey(UserUtil.PREFIX_USERNAME + username);
// 先删除
ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID + userId);
ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_USERNAME + username);
// 清除空拦截
CacheUtil.delNilFlag(UserUtil.PREFIX_ID + userId);
CacheUtil.delNilFlag(UserUtil.PREFIX_USERNAME + username);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKeyById);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKeyByName);
}
/**
@ -113,10 +113,10 @@ public class UserHandler implements RedisPushSubHandler{
return;
}
String cacheKey = CacheUtil.handleKey(UserUtil.PREFIX_ID_ROLES + userId);
// 先删除
ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID_ROLES + userId);
// 清除空拦截
CacheUtil.delNilFlag(UserUtil.PREFIX_ID_ROLES + userId);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
}
/**
@ -136,10 +136,10 @@ public class UserHandler implements RedisPushSubHandler{
return;
}
String cacheKey = CacheUtil.handleKey(UserUtil.PREFIX_ID_PERMISSIONS + userId);
// 先删除
ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID_PERMISSIONS + userId);
// 清除空拦截
CacheUtil.delNilFlag(UserUtil.PREFIX_ID_PERMISSIONS + userId);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
}
/**
@ -159,10 +159,10 @@ public class UserHandler implements RedisPushSubHandler{
return;
}
String cacheKey = CacheUtil.handleKey(UserUtil.PREFIX_ID_MENUS + userId);
// 先删除
ehCachePlugin.delete(CacheConstants.HOT_DATA, UserUtil.PREFIX_ID_MENUS + userId);
// 清除空拦截
CacheUtil.delNilFlag(UserUtil.PREFIX_ID_MENUS + userId);
ehCachePlugin.delete(CacheConstants.EHCACHE_SPACE, cacheKey);
}

@ -18,7 +18,8 @@ package org.opsli.core.cache.pushsub.msgs;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.experimental.Accessors;
import org.opsli.core.cache.pushsub.enums.CacheType;
import org.opsli.core.cache.pushsub.entity.CacheDataEntity;
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
import org.opsli.core.cache.pushsub.enums.PushSubType;
import org.opsli.core.cache.pushsub.receiver.RedisPushSubReceiver;
@ -37,23 +38,24 @@ import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
public final class CacheDataMsgFactory extends BaseSubMessage{
/** 通道 */
private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL+RedisPushSubReceiver.CHANNEL;
private static final String CHANNEL = RedisPushSubReceiver.BASE_CHANNEL + RedisPushSubReceiver.CHANNEL;
private CacheDataMsgFactory(){}
/**
*
*/
public static BaseSubMessage createMsg(PushSubType py,String key, Object value, CacheType cacheType){
public static BaseSubMessage createMsg(CacheDataEntity cacheDataEntity, Object value, CacheHandleType cacheHandleType){
BaseSubMessage baseSubMessage = new BaseSubMessage();
// 数据
JSONObject jsonObj = new JSONObject();
jsonObj.put(MsgArgsType.CACHE_DATA_KEY.toString(),key);
jsonObj.put(MsgArgsType.CACHE_DATA_KEY.toString(),cacheDataEntity.getKey());
jsonObj.put(MsgArgsType.CACHE_DATA_NAME.toString(),cacheDataEntity.getCacheName());
jsonObj.put(MsgArgsType.CACHE_DATA_VALUE.toString(),value);
jsonObj.put(MsgArgsType.CACHE_DATA_TYPE.toString(),cacheType.toString());
jsonObj.put(MsgArgsType.CACHE_DATA_TYPE.toString(), cacheHandleType.toString());
// 热点数据 - 系统数据
baseSubMessage.build(CHANNEL,py.toString(),jsonObj);
baseSubMessage.build(CHANNEL,PushSubType.HOT_DATA.toString(),jsonObj);
return baseSubMessage;
}

@ -19,7 +19,7 @@ import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.experimental.Accessors;
import org.opsli.api.wrapper.system.dict.DictWrapper;
import org.opsli.core.cache.pushsub.enums.CacheType;
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
import org.opsli.core.cache.pushsub.enums.DictModelType;
import org.opsli.core.cache.pushsub.enums.MsgArgsType;
import org.opsli.core.cache.pushsub.enums.PushSubType;
@ -48,13 +48,13 @@ public final class DictMsgFactory extends BaseSubMessage{
/**
*
*/
public static BaseSubMessage createMsg(DictWrapper dictWrapperModel, CacheType cacheType){
public static BaseSubMessage createMsg(DictWrapper dictWrapperModel, CacheHandleType cacheHandleType){
BaseSubMessage baseSubMessage = new BaseSubMessage();
// 数据
JSONObject jsonObj = new JSONObject();
jsonObj.put(MsgArgsType.DICT_MODEL.toString(), dictWrapperModel);
jsonObj.put(MsgArgsType.DICT_MODEL_TYPE.toString(), DictModelType.OBJECT);
jsonObj.put(MsgArgsType.DICT_TYPE.toString(),cacheType.toString());
jsonObj.put(MsgArgsType.DICT_TYPE.toString(), cacheHandleType.toString());
// DICT 字典
baseSubMessage.build(CHANNEL,PushSubType.DICT.toString(),jsonObj);
@ -64,13 +64,13 @@ public final class DictMsgFactory extends BaseSubMessage{
/**
*
*/
public static BaseSubMessage createMsg(List<DictWrapper> dictWrapperModels, CacheType cacheType){
public static BaseSubMessage createMsg(List<DictWrapper> dictWrapperModels, CacheHandleType cacheHandleType){
BaseSubMessage baseSubMessage = new BaseSubMessage();
// 数据
JSONObject jsonObj = new JSONObject();
jsonObj.put(MsgArgsType.DICT_MODELS.toString(), dictWrapperModels);
jsonObj.put(MsgArgsType.DICT_MODEL_TYPE.toString(), DictModelType.COLLECTION);
jsonObj.put(MsgArgsType.DICT_TYPE.toString(),cacheType.toString());
jsonObj.put(MsgArgsType.DICT_TYPE.toString(), cacheHandleType.toString());
// DICT 字典
baseSubMessage.build(CHANNEL,PushSubType.DICT.toString(),jsonObj);

@ -16,6 +16,7 @@
package org.opsli.core.filters.aspect;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
@ -27,12 +28,9 @@ import org.opsli.api.base.warpper.ApiWrapper;
import org.opsli.common.annotation.hotdata.EnableHotData;
import org.opsli.common.annotation.hotdata.HotDataDel;
import org.opsli.common.annotation.hotdata.HotDataPut;
import org.opsli.common.constants.CacheConstants;
import org.opsli.common.utils.Props;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.cache.pushsub.entity.CacheDataEntity;
import org.opsli.core.cache.pushsub.enums.CacheType;
import org.opsli.core.cache.pushsub.enums.PushSubType;
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
import org.opsli.core.cache.pushsub.msgs.CacheDataMsgFactory;
import org.opsli.plugins.redis.RedisPlugin;
import org.springframework.beans.factory.annotation.Autowired;
@ -58,15 +56,6 @@ import static org.opsli.common.constants.OrderConstants.HOT_DATA_ORDER;
@Component
public class CacheDataAop {
/** 热点数据前缀 */
public static final String PREFIX_NAME;
static{
// 缓存前缀
Props props = new Props("application.yaml");
PREFIX_NAME = props.getStr("spring.cache-conf.prefix",CacheConstants.PREFIX_NAME) + ":";
}
@Autowired
private RedisPlugin redisPlugin;
@ -94,7 +83,9 @@ public class CacheDataAop {
return returnValue;
}
List<CacheDataEntity> cacheDataEntityList = this.putHandlerData(point, returnValue);
String simpleName = point.getTarget().getClass().getSimpleName();
List<CacheDataEntity> cacheDataEntityList = this.putHandlerData(point, returnValue, simpleName);
// 非法判断
if(CollUtil.isEmpty(cacheDataEntityList)){
return returnValue;
@ -103,18 +94,12 @@ public class CacheDataAop {
for (CacheDataEntity cacheDataEntity : cacheDataEntityList) {
// 更新缓存数据
// 热点数据
if(CacheConstants.HOT_DATA.equals(cacheDataEntity.getCacheName())){
CacheUtil.putByKeyOriginal(cacheDataEntity.getKey(), returnValue);
}
// 永久数据
else if(CacheConstants.EDEN_DATA.equals(cacheDataEntity.getCacheName())) {
CacheUtil.putEdenByKeyOriginal(cacheDataEntity.getKey(), returnValue);
}
CacheUtil.put(cacheDataEntity.getKey(), returnValue);
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
CacheDataMsgFactory.createMsg(cacheDataEntity.getType(),
cacheDataEntity.getKey(), returnValue, CacheType.UPDATE)
CacheDataMsgFactory.createMsg(
cacheDataEntity, returnValue, CacheHandleType.UPDATE)
);
}
@ -138,6 +123,8 @@ public class CacheDataAop {
return returnValue;
}
String simpleName = point.getTarget().getClass().getSimpleName();
// 删除状态判断
try {
Boolean ret = (Boolean) returnValue;
@ -149,7 +136,7 @@ public class CacheDataAop {
return returnValue;
}
List<CacheDataEntity> cacheDataEntityList = this.delHandlerData(point, args);
List<CacheDataEntity> cacheDataEntityList = this.delHandlerData(point, args, simpleName);
// 非法判断
if(CollUtil.isEmpty(cacheDataEntityList)){
return returnValue;
@ -161,8 +148,8 @@ public class CacheDataAop {
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
CacheDataMsgFactory.createMsg(cacheDataEntity.getType(),
cacheDataEntity.getKey(), returnValue, CacheType.DELETE)
CacheDataMsgFactory.createMsg(
cacheDataEntity, returnValue, CacheHandleType.DELETE)
);
}
@ -177,7 +164,7 @@ public class CacheDataAop {
* PUT
* @param point
*/
private List<CacheDataEntity> putHandlerData(ProceedingJoinPoint point, Object returnValue){
private List<CacheDataEntity> putHandlerData(ProceedingJoinPoint point, Object returnValue, String simpleName){
// 这里 只对 继承了 ApiWrapper 的类做处理
if(!(returnValue instanceof ApiWrapper)){
return null;
@ -195,24 +182,15 @@ public class CacheDataAop {
}
// 获取注解参数
HotDataPut aCache= objMethod.getAnnotation(HotDataPut.class);
HotDataPut aCache = objMethod.getAnnotation(HotDataPut.class);
if(aCache != null){
// 获得缓存类型
PushSubType type = this.judgeCacheType(aCache.name());
if(type == null) {
// 如果都不是 则直接退出 不走缓存
return null;
}
// key 前缀
StringBuilder keyBuf = this.judgeCacheKeyBuf(aCache.name());
// 这里 只对 继承了 BaseEntity 的类做处理
ApiWrapper apiWrapper = (ApiWrapper) returnValue;
// key 存储ID
String key = keyBuf.append(apiWrapper.getId()).toString();
// 热数据 前缀增加 方法类名称 减小ID 冲撞
String cacheKey = CacheUtil.handleKey(simpleName +":"+ apiWrapper.getId());
CacheDataEntity ret = new CacheDataEntity(key, type ,aCache.name());
CacheDataEntity ret = new CacheDataEntity(apiWrapper.getId() , cacheKey);
// 存放数据
this.putCacheData(cacheDataEntities, ret);
@ -229,7 +207,7 @@ public class CacheDataAop {
* DEL
* @param point
*/
private List<CacheDataEntity> delHandlerData(ProceedingJoinPoint point, Object[] args){
private List<CacheDataEntity> delHandlerData(ProceedingJoinPoint point, Object[] args, String simpleName){
if(args == null || args.length == 0){
return null;
}
@ -248,54 +226,41 @@ public class CacheDataAop {
// 获取注解参数
HotDataDel aCache= objMethod.getAnnotation(HotDataDel.class);
if(aCache != null){
// 获得缓存类型
PushSubType type = this.judgeCacheType(aCache.name());
if(type == null) {
// 如果都不是 则直接退出 不走缓存
return null;
}
// key 前缀
StringBuilder keyBuf = this.judgeCacheKeyBuf(aCache.name());
List<String> keyList = null;
// 处理数据
for (Object arg : args) {
if (arg instanceof String) {
// key 存储ID
String key = keyBuf.toString() + arg;
CacheDataEntity ret = new CacheDataEntity(key, type ,aCache.name());
// 存放数据
this.putCacheData(cacheDataEntities, ret);
} else if (arg instanceof String[]) {
String[] ids = (String[]) arg;
for (String id : ids) {
// key 存储ID
String key = keyBuf.toString() + id;
CacheDataEntity ret = new CacheDataEntity(key, type ,aCache.name());
// 存放数据
this.putCacheData(cacheDataEntities, ret);
}
} else if (arg instanceof ApiWrapper) {
if (arg instanceof ApiWrapper) {
// key 存储ID
ApiWrapper apiWrapper = (ApiWrapper) arg;
String key = keyBuf.toString() + apiWrapper.getId();
CacheDataEntity ret = new CacheDataEntity(key, type ,aCache.name());
// 存放数据
this.putCacheData(cacheDataEntities, ret);
ApiWrapper apiWrapper = Convert.convert(ApiWrapper.class, arg);
keyList = Convert.toList(String.class, apiWrapper.getId());
} else if (arg instanceof Collection) {
try {
Collection<ApiWrapper> baseEntityList = (Collection<ApiWrapper>) arg;
keyList = Lists.newArrayList();
List<ApiWrapper> baseEntityList = Convert.toList(ApiWrapper.class, arg);
for (ApiWrapper baseEntity : baseEntityList) {
// key 存储ID
String key = keyBuf.toString() + baseEntity.getId();
CacheDataEntity ret = new CacheDataEntity(key, type ,aCache.name());
// 存放数据
this.putCacheData(cacheDataEntities, ret);
keyList.add(baseEntity.getId());
}
}catch (Exception e){
log.error(e.getMessage(),e);
}
}else {
keyList = Convert.toList(String.class, arg);
}
}
if(keyList != null && CollUtil.isNotEmpty(keyList)){
for (String key : keyList) {
// 热数据 前缀增加 方法类名称 减小ID 冲撞
String cacheKey = CacheUtil.handleKey(simpleName +":"+ key);
CacheDataEntity ret = new CacheDataEntity(key , cacheKey);
// 存放数据
this.putCacheData(cacheDataEntities, ret);
}
}
return cacheDataEntities;
}
}catch (Exception e){
@ -336,41 +301,5 @@ public class CacheDataAop {
cacheDataList.add(cacheData);
}
/**
* Key
* @param cacheName
* @return
*/
private StringBuilder judgeCacheKeyBuf(String cacheName){
// key 前缀
StringBuilder keyBuf = new StringBuilder(PREFIX_NAME);
// 热点数据
if(CacheConstants.HOT_DATA.equals(cacheName)){
keyBuf.append(CacheConstants.HOT_DATA).append(":");
}
// 系统数据
else if(CacheConstants.EDEN_DATA.equals(cacheName)){
keyBuf.append(CacheConstants.EDEN_DATA).append(":");
}
return keyBuf;
}
/**
*
* @param cacheName
* @return
*/
private PushSubType judgeCacheType(String cacheName){
PushSubType type = null;
// 热点数据
if(CacheConstants.HOT_DATA.equals(cacheName)){
type = PushSubType.HOT_DATA;
}
// 系统数据
else if(CacheConstants.EDEN_DATA.equals(cacheName)){
type = PushSubType.EDEN_DATA;
}
return type;
}
}

@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import org.opsli.common.constants.CacheConstants;
import org.opsli.common.exception.TokenException;
import org.opsli.common.utils.Props;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.msg.TokenMsg;
import org.opsli.plugins.redis.RedisPlugin;
import org.springframework.beans.factory.annotation.Autowired;
@ -50,18 +51,11 @@ public class CaptchaUtil{
private static RedisPlugin redisPlugin;
/** 谷歌验证码 */
private static Producer producer;
/** 热点数据前缀 */
public static final String PREFIX_NAME;
static{
// 缓存前缀
Props props = new Props("application.yaml");
PREFIX_NAME = props.getStr("spring.cache-conf.prefix", CacheConstants.PREFIX_NAME) + ":";
}
/**
*
* @param uuid
* @return
* @param uuid UUID
* @return BufferedImage
*/
public static BufferedImage getCaptcha(String uuid) {
if(StringUtils.isBlank(uuid)){
@ -71,7 +65,7 @@ public class CaptchaUtil{
//生成文字验证码
String code = producer.createText();
boolean ret = redisPlugin.put(PREFIX_NAME + PREFIX + uuid, code, TIME_OUT);
boolean ret = redisPlugin.put(CacheUtil.PREFIX_NAME + PREFIX + uuid, code, TIME_OUT);
if(ret){
return producer.createImage(code);
@ -81,9 +75,8 @@ public class CaptchaUtil{
/**
*
* @param uuid
* @param code
* @return
* @param uuid UUID
* @param code CODE
*/
public static void validate(String uuid, String code) {
// 判断UUID 是否为空
@ -97,7 +90,7 @@ public class CaptchaUtil{
}
// 验证码
String codeTemp = (String) redisPlugin.get(PREFIX_NAME + PREFIX + uuid);
String codeTemp = (String) redisPlugin.get(CacheUtil.PREFIX_NAME + PREFIX + uuid);
if(StringUtils.isEmpty(codeTemp)){
throw new TokenException(TokenMsg.EXCEPTION_CAPTCHA_NULL);
}
@ -112,8 +105,8 @@ public class CaptchaUtil{
/**
*
* @param uuid
* @return
* @param uuid UUID
* @return boolean
*/
public static boolean delCaptcha(String uuid) {
if(StringUtils.isEmpty(uuid)){
@ -121,7 +114,7 @@ public class CaptchaUtil{
}
//删除验证码
return redisPlugin.del(PREFIX_NAME + PREFIX + uuid);
return redisPlugin.del(CacheUtil.PREFIX_NAME + PREFIX + uuid);
}

@ -27,6 +27,7 @@ import org.opsli.api.wrapper.system.dict.DictDetailModel;
import org.opsli.api.wrapper.system.dict.DictWrapper;
import org.opsli.common.constants.CacheConstants;
import org.opsli.common.constants.DictConstants;
import org.opsli.common.enums.CacheType;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.plugins.redis.RedisLockPlugins;
import org.opsli.plugins.redis.RedisPlugin;
@ -75,8 +76,8 @@ public class DictUtil {
public static String getDictNameByValue(String typeCode, String dictValue, String defaultVal){
String dictName = "";
DictDetailModel cacheModel = CacheUtil.getHash(DictConstants.CACHE_PREFIX_VALUE + typeCode,
dictValue, DictDetailModel.class);
DictDetailModel cacheModel = CacheUtil.getHash(DictDetailModel.class, DictConstants.CACHE_PREFIX_VALUE + typeCode,
dictValue);
if (cacheModel != null){
dictName = cacheModel.getDictName();
}
@ -108,8 +109,8 @@ public class DictUtil {
}
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
cacheModel = CacheUtil.getHash(DictConstants.CACHE_PREFIX_VALUE + typeCode,
dictValue, DictDetailModel.class);
cacheModel = CacheUtil.getHash(DictDetailModel.class, DictConstants.CACHE_PREFIX_VALUE + typeCode,
dictValue);
if (cacheModel != null){
dictName = cacheModel.getDictName();
}
@ -165,8 +166,8 @@ public class DictUtil {
public static String getDictValueByName(String typeCode, String dictName, String defaultVal){
String dictValue = "";
DictDetailModel cacheModel = CacheUtil.getHash(DictConstants.CACHE_PREFIX_NAME + typeCode,
dictName, DictDetailModel.class);
DictDetailModel cacheModel = CacheUtil.getHash(DictDetailModel.class, DictConstants.CACHE_PREFIX_NAME + typeCode,
dictName);
if (cacheModel != null){
dictValue = cacheModel.getDictValue();
}
@ -195,8 +196,8 @@ public class DictUtil {
}
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
cacheModel = CacheUtil.getHash(DictConstants.CACHE_PREFIX_NAME + typeCode,
dictName, DictDetailModel.class);
cacheModel = CacheUtil.getHash(DictDetailModel.class, DictConstants.CACHE_PREFIX_NAME + typeCode,
dictName);
if (cacheModel != null){
dictValue = cacheModel.getDictValue();
}
@ -251,7 +252,7 @@ public class DictUtil {
public static List<DictWrapper> getDictList(String typeCode){
List<DictWrapper> dictWrapperModels = Lists.newArrayList();
try {
String key = CacheUtil.handleKey(CacheConstants.EDEN_HASH_DATA, DictConstants.CACHE_PREFIX_VALUE + typeCode);
String key = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_VALUE + typeCode);
Map<Object, Object> dictMap = redisPlugin.hGetAll(key);
Set<Map.Entry<Object, Object>> entries = dictMap.entrySet();
for (Map.Entry<Object, Object> entry : entries) {
@ -297,7 +298,7 @@ public class DictUtil {
}
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
key = CacheUtil.handleKey(CacheConstants.EDEN_HASH_DATA, DictConstants.CACHE_PREFIX_VALUE + typeCode);
key = CacheUtil.handleKey(CacheType.EDEN_HASH, DictConstants.CACHE_PREFIX_VALUE + typeCode);
dictMap = redisPlugin.hGetAll(key);
entries = dictMap.entrySet();
for (Map.Entry<Object, Object> entry : entries) {
@ -315,6 +316,7 @@ public class DictUtil {
dictWrapperModel.setTypeCode(typeCode);
dictWrapperModel.setDictName(model.getDictName());
dictWrapperModel.setDictValue(model.getDictValue());
dictWrapperModel.setModel(model);
dictWrapperModels.add(dictWrapperModel);
}
if(!dictWrapperModels.isEmpty()){
@ -397,9 +399,9 @@ public class DictUtil {
// 清除缓存
DictUtil.del(model);
CacheUtil.putEdenHash(DictConstants.CACHE_PREFIX_NAME + model.getTypeCode(),
CacheUtil.putHash(DictConstants.CACHE_PREFIX_NAME + model.getTypeCode(),
model.getDictName(), model.getModel());
CacheUtil.putEdenHash(DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode(),
CacheUtil.putHash(DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode(),
model.getDictValue(), model.getModel());
}
@ -418,12 +420,12 @@ public class DictUtil {
boolean hasNilFlagByValue = CacheUtil.hasNilFlag(DictConstants.CACHE_PREFIX_VALUE +
model.getTypeCode() + ":" + model.getDictValue());
DictWrapper dictByName = CacheUtil.getHash(DictConstants.CACHE_PREFIX_NAME + model.getTypeCode(),
model.getDictName(),
DictWrapper.class);
DictWrapper dictByValue = CacheUtil.getHash(DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode(),
model.getDictValue(),
DictWrapper.class);
DictWrapper dictByName = CacheUtil.getHash(DictWrapper.class,
DictConstants.CACHE_PREFIX_NAME + model.getTypeCode(),
model.getDictName());
DictWrapper dictByValue = CacheUtil.getHash(DictWrapper.class,
DictConstants.CACHE_PREFIX_VALUE + model.getTypeCode(),
model.getDictValue());
// 计数器
int count = 0;
@ -450,7 +452,7 @@ public class DictUtil {
if (dictByName != null){
count++;
// 清除空拦截
boolean tmp = CacheUtil.delEdenHash(DictConstants.CACHE_PREFIX_NAME +
boolean tmp = CacheUtil.delHash(DictConstants.CACHE_PREFIX_NAME +
model.getTypeCode(), model.getDictName());
if(tmp){
count--;
@ -460,7 +462,7 @@ public class DictUtil {
if (dictByValue != null){
count++;
// 清除空拦截
boolean tmp = CacheUtil.delEdenHash(DictConstants.CACHE_PREFIX_VALUE +
boolean tmp = CacheUtil.delHash(DictConstants.CACHE_PREFIX_VALUE +
model.getTypeCode(), model.getDictValue());
if(tmp){
count--;

@ -67,7 +67,7 @@ public class MenuUtil {
*/
public static MenuModel getMenuByCode(String menuCode){
// 先从缓存里拿
MenuModel menuModel = CacheUtil.get(PREFIX_CODE + menuCode, MenuModel.class);
MenuModel menuModel = CacheUtil.getTimed(MenuModel.class, PREFIX_CODE + menuCode);
if (menuModel != null){
return menuModel;
}
@ -94,7 +94,7 @@ public class MenuUtil {
}
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
menuModel = CacheUtil.get(PREFIX_CODE + menuCode, MenuModel.class);
menuModel = CacheUtil.getTimed(MenuModel.class, PREFIX_CODE + menuCode);
if (menuModel != null){
return menuModel;
}
@ -138,7 +138,7 @@ public class MenuUtil {
// 计数器
int count = 0;
MenuModel menuModel = CacheUtil.get(PREFIX_CODE + menu.getMenuCode(), MenuModel.class);
MenuModel menuModel = CacheUtil.getTimed(MenuModel.class, PREFIX_CODE + menu.getMenuCode());
boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_CODE + menu.getMenuCode());
// 只要不为空 则执行刷新

@ -66,7 +66,7 @@ public class OrgUtil {
*/
public static UserOrgRefModel getOrgByUserId(String userId){
// 先从缓存里拿
UserOrgRefModel orgRefModel = CacheUtil.get(PREFIX_CODE + userId, UserOrgRefModel.class);
UserOrgRefModel orgRefModel = CacheUtil.getTimed(UserOrgRefModel.class, PREFIX_CODE + userId);
if (orgRefModel != null){
return orgRefModel;
}
@ -93,7 +93,7 @@ public class OrgUtil {
}
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
orgRefModel = CacheUtil.get(PREFIX_CODE + userId, UserOrgRefModel.class);
orgRefModel = CacheUtil.getTimed(UserOrgRefModel.class, PREFIX_CODE + userId);
if (orgRefModel != null){
return orgRefModel;
}
@ -137,7 +137,7 @@ public class OrgUtil {
// 计数器
int count = 0;
UserOrgRefModel orgRefModel = CacheUtil.get(PREFIX_CODE + userId, UserOrgRefModel.class);
UserOrgRefModel orgRefModel = CacheUtil.getTimed(UserOrgRefModel.class, PREFIX_CODE + userId);
boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_CODE + userId);
// 只要不为空 则执行刷新

@ -19,9 +19,7 @@ import cn.hutool.core.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.common.constants.CacheConstants;
import org.opsli.common.utils.Props;
import org.opsli.plugins.redis.RedisLockPlugins;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.plugins.redis.RedisPlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
@ -50,20 +48,11 @@ public class SearchHisUtil {
/** 搜索历史缓存数据KEY */
private static final int DEFAULT_COUNT = 10;
/**
*
*/
public static final String PREFIX_NAME;
private static final String CACHE_PREFIX = "his:username:";
/** Redis插件 */
private static RedisPlugin redisPlugin;
static {
Props props = new Props("application.yaml");
PREFIX_NAME = props.getStr("spring.cache-conf.prefix", CacheConstants.PREFIX_NAME) + ":";
}
/**
*
@ -82,7 +71,7 @@ public class SearchHisUtil {
// 获得当前用户
UserModel user = UserUtil.getUser();
String cacheKey = PREFIX_NAME + CACHE_PREFIX + user.getUsername() + ":" + key;
String cacheKey = CacheUtil.PREFIX_NAME + CACHE_PREFIX + user.getUsername() + ":" + key;
return redisPlugin.zReverseRange(cacheKey, 0, count - 1);
}
@ -108,7 +97,7 @@ public class SearchHisUtil {
}
String cacheKey = PREFIX_NAME + CACHE_PREFIX + user.getUsername() + ":" + key;
String cacheKey = CacheUtil.PREFIX_NAME + CACHE_PREFIX + user.getUsername() + ":" + key;
String val = values[0];
// 记录

@ -67,7 +67,7 @@ public class TenantUtil {
*/
public static TenantModel getTenant(String tenantId){
// 先从缓存里拿
TenantModel tenantModel = CacheUtil.get(PREFIX_CODE + tenantId, TenantModel.class);
TenantModel tenantModel = CacheUtil.getTimed(TenantModel.class, PREFIX_CODE + tenantId);
if (tenantModel != null){
return tenantModel;
}
@ -94,7 +94,7 @@ public class TenantUtil {
}
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
tenantModel = CacheUtil.get(PREFIX_CODE + tenantId, TenantModel.class);
tenantModel = CacheUtil.getTimed(TenantModel.class, PREFIX_CODE + tenantId);
if (tenantModel != null){
return tenantModel;
}
@ -138,7 +138,7 @@ public class TenantUtil {
// 计数器
int count = 0;
TenantModel tenantModel = CacheUtil.get(PREFIX_CODE + tenantId, TenantModel.class);
TenantModel tenantModel = CacheUtil.getTimed(TenantModel.class, PREFIX_CODE + tenantId);
boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_CODE + tenantId);
// 只要不为空 则执行刷新

@ -33,6 +33,7 @@ import org.opsli.common.constants.TokenTypeConstants;
import org.opsli.common.exception.TokenException;
import org.opsli.common.utils.Props;
import org.opsli.core.autoconfigure.properties.GlobalProperties;
import org.opsli.core.cache.local.CacheUtil;
import org.opsli.core.msg.TokenMsg;
import org.opsli.plugins.redis.RedisPlugin;
import org.springframework.beans.factory.annotation.Autowired;
@ -76,18 +77,12 @@ public class UserTokenUtil {
/** Redis插件 */
private static RedisPlugin redisPlugin;
/** 热点数据前缀 */
public static final String PREFIX_NAME;
static{
// 缓存前缀
Props props = new Props("application.yaml");
PREFIX_NAME = props.getStr("spring.cache-conf.prefix", CacheConstants.PREFIX_NAME) + ":";
TICKET_PREFIX = PREFIX_NAME + "ticket:";
ACCOUNT_SLIP_COUNT_PREFIX = PREFIX_NAME + "account:slip:count:";
ACCOUNT_SLIP_LOCK_PREFIX = PREFIX_NAME + "account:slip:lock:";
TICKET_PREFIX = CacheUtil.PREFIX_NAME + "ticket:";
ACCOUNT_SLIP_COUNT_PREFIX = CacheUtil.PREFIX_NAME + "account:slip:count:";
ACCOUNT_SLIP_LOCK_PREFIX = CacheUtil.PREFIX_NAME + "account:slip:lock:";
}

@ -105,7 +105,7 @@ public class UserUtil {
*/
public static UserModel getUser(String userId){
// 先从缓存里拿
UserModel userModel = CacheUtil.get(PREFIX_ID + userId, UserModel.class);
UserModel userModel = CacheUtil.getTimed(UserModel.class, PREFIX_ID + userId);
if (userModel != null){
return userModel;
}
@ -133,7 +133,7 @@ public class UserUtil {
}
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
userModel = CacheUtil.get(PREFIX_ID + userId, UserModel.class);
userModel = CacheUtil.getTimed(UserModel.class, PREFIX_ID + userId);
if (userModel != null){
return userModel;
}
@ -173,7 +173,7 @@ public class UserUtil {
*/
public static UserModel getUserByUserName(String userName){
// 先从缓存里拿
UserModel userModel = CacheUtil.get(PREFIX_USERNAME + userName, UserModel.class);
UserModel userModel = CacheUtil.getTimed(UserModel.class, PREFIX_USERNAME + userName);
if (userModel != null){
return userModel;
}
@ -200,7 +200,7 @@ public class UserUtil {
}
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
userModel = CacheUtil.get(PREFIX_USERNAME + userName, UserModel.class);
userModel = CacheUtil.getTimed(UserModel.class, PREFIX_USERNAME + userName);
if (userModel != null){
return userModel;
}
@ -238,7 +238,7 @@ public class UserUtil {
// 先从缓存里拿
try {
Object obj = CacheUtil.get(PREFIX_ID_ROLES + userId);
Object obj = CacheUtil.getTimed(PREFIX_ID_ROLES + userId);
if(obj instanceof List){
List<String> list = Convert.toList(String.class, obj);
if (!list.isEmpty()) {
@ -277,7 +277,7 @@ public class UserUtil {
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
try {
Object obj = CacheUtil.get(PREFIX_ID_ROLES + userId);
Object obj = CacheUtil.getTimed(PREFIX_ID_ROLES + userId);
if(obj instanceof List){
List<String> list = Convert.toList(String.class, obj);
if (!list.isEmpty()) {
@ -325,7 +325,7 @@ public class UserUtil {
// 先从缓存里拿
try {
Object obj = CacheUtil.get(PREFIX_ID_PERMISSIONS + userId);
Object obj = CacheUtil.getTimed(PREFIX_ID_PERMISSIONS + userId);
if(obj instanceof List){
List<String> list = Convert.toList(String.class, obj);
if (!list.isEmpty()) {
@ -365,7 +365,7 @@ public class UserUtil {
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
try {
Object obj = CacheUtil.get(PREFIX_ID_PERMISSIONS + userId);
Object obj = CacheUtil.getTimed(PREFIX_ID_PERMISSIONS + userId);
if(obj instanceof List){
List<String> list = Convert.toList(String.class, obj);
if (!list.isEmpty()) {
@ -412,7 +412,7 @@ public class UserUtil {
// 先从缓存里拿
try {
Object obj = CacheUtil.get(PREFIX_ID_MENUS + userId);
Object obj = CacheUtil.getTimed(PREFIX_ID_MENUS + userId);
if(obj instanceof List){
List<?> list = Convert.toList(obj);
if (!list.isEmpty()) {
@ -462,7 +462,7 @@ public class UserUtil {
// 如果获得锁 则 再次检查缓存里有没有, 如果有则直接退出, 没有的话才发起数据库请求
try {
Object obj = CacheUtil.get(PREFIX_ID_MENUS + userId);
Object obj = CacheUtil.getTimed(PREFIX_ID_MENUS + userId);
if(obj instanceof List){
List<?> list = Convert.toList(obj);
if (!list.isEmpty()) {
@ -521,9 +521,8 @@ public class UserUtil {
return true;
}
UserModel userModelById = CacheUtil.get(PREFIX_ID + user.getId(), UserModel.class);
UserModel userModelByUsername = CacheUtil.get(PREFIX_USERNAME + user.getUsername(),
UserModel.class);
UserModel userModelById = CacheUtil.getTimed(UserModel.class, PREFIX_ID + user.getId());
UserModel userModelByUsername = CacheUtil.getTimed(UserModel.class, PREFIX_USERNAME + user.getUsername());
boolean hasNilFlagById = CacheUtil.hasNilFlag(PREFIX_ID + user.getId());
boolean hasNilFlagByName = CacheUtil.hasNilFlag(PREFIX_USERNAME + user.getUsername());
@ -583,7 +582,7 @@ public class UserUtil {
* @return boolean
*/
public static boolean refreshUserRoles(String userId){
Object obj = CacheUtil.get(PREFIX_ID_ROLES + userId);
Object obj = CacheUtil.getTimed(PREFIX_ID_ROLES + userId);
boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_ID_ROLES + userId);
// 计数器
@ -622,7 +621,7 @@ public class UserUtil {
* @return boolean
*/
public static boolean refreshUserAllPerms(String userId){
Object obj = CacheUtil.get(PREFIX_ID_PERMISSIONS + userId);
Object obj = CacheUtil.getTimed(PREFIX_ID_PERMISSIONS + userId);
boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_ID_PERMISSIONS + userId);
// 计数器
@ -661,7 +660,7 @@ public class UserUtil {
* @return boolean
*/
public static boolean refreshUserMenus(String userId){
Object obj = CacheUtil.get(PREFIX_ID_MENUS + userId);
Object obj = CacheUtil.getTimed(PREFIX_ID_MENUS + userId);
boolean hasNilFlag = CacheUtil.hasNilFlag(PREFIX_ID_MENUS + userId);
// 计数器

@ -56,7 +56,9 @@ public enum DataBaseType {
return this.desc;
}
private DataBaseType(final String db, final String desc) {
// ================
DataBaseType(final String db, final String desc) {
this.db = db;
this.desc = desc;
}

@ -27,7 +27,7 @@ import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.cache.pushsub.enums.CacheType;
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
import org.opsli.core.cache.pushsub.msgs.DictMsgFactory;
import org.opsli.core.msg.CoreMsg;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
@ -99,7 +99,7 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE)
DictMsgFactory.createMsg(dictWrapperList, CacheHandleType.DELETE)
);
}
}
@ -146,7 +146,7 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE)
DictMsgFactory.createMsg(dictWrapperList, CacheHandleType.DELETE)
);
}
}
@ -182,7 +182,7 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
));
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE)
DictMsgFactory.createMsg(dictWrapperList, CacheHandleType.DELETE)
);
}
}
@ -221,7 +221,7 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
));
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE)
DictMsgFactory.createMsg(dictWrapperList, CacheHandleType.DELETE)
);
}
}
@ -267,7 +267,7 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperModels, CacheType.DELETE)
DictMsgFactory.createMsg(dictWrapperModels, CacheHandleType.DELETE)
);
}
@ -321,7 +321,7 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperModels, CacheType.DELETE)
DictMsgFactory.createMsg(dictWrapperModels, CacheHandleType.DELETE)
);
}
}
@ -364,7 +364,7 @@ public class DictDetailServiceImpl extends CrudServiceImpl<DictDetailMapper, Sys
));
// 广播缓存数据 - 通知其他服务器同步数据
redisPlugin.sendMessage(
DictMsgFactory.createMsg(dictWrapperList, CacheType.DELETE)
DictMsgFactory.createMsg(dictWrapperList, CacheHandleType.DELETE)
);
}
}

@ -12,7 +12,7 @@ import org.opsli.api.wrapper.system.dict.DictWrapper;
import org.opsli.api.wrapper.test.TestModel;
import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.base.controller.BaseRestController;
import org.opsli.core.cache.pushsub.enums.CacheType;
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
import org.opsli.core.cache.pushsub.msgs.DictMsgFactory;
import org.opsli.core.persistence.Page;
import org.opsli.core.persistence.querybuilder.QueryBuilder;
@ -85,7 +85,7 @@ public class TestRestRestController extends BaseRestController<TestEntity, TestM
public ResultVo<?> sendMsg(){
DictWrapper model = new DictWrapper();
BaseSubMessage msg = DictMsgFactory.createMsg(model, CacheType.UPDATE);
BaseSubMessage msg = DictMsgFactory.createMsg(model, CacheHandleType.UPDATE);
boolean ret = redisPlugin.sendMessage(msg);
if(ret){

@ -46,7 +46,7 @@ public class EhCachePluginImpl implements EhCachePlugin {
@Override
public boolean put(String cacheName, String key, Object value) {
if(cacheManager == null){
return false;
return true;
}
boolean ret = false;
try {
@ -98,7 +98,7 @@ public class EhCachePluginImpl implements EhCachePlugin {
@Override
public boolean delete(String cacheName, String key) {
if(cacheManager == null){
return false;
return true;
}
boolean ret = false;
try {

@ -16,9 +16,6 @@
package org.opsli.plugins.redis.lock;
import org.opsli.common.constants.CacheConstants;
import org.opsli.common.utils.Props;
import java.util.concurrent.atomic.AtomicInteger;
/**
@ -30,17 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public class RedisLock {
private static final String LOCK_PREFIX;
/** 热点数据前缀 */
public static final String PREFIX_NAME;
static {
// 缓存前缀
Props props = new Props("application.yaml");
PREFIX_NAME = props.getStr("spring.cache-conf.prefix", CacheConstants.PREFIX_NAME) + ":";
LOCK_PREFIX = PREFIX_NAME + "lock:";
}
private static final String LOCK_PREFIX = "lock:";
/** 锁名称 */
private String lockName;
@ -127,4 +114,6 @@ public class RedisLock {
this.identifier = identifier;
return this;
}
}

@ -8,7 +8,7 @@ spring:
#redis 配置
redis:
database: 0
host: 127.0.0.1
host: 10.0.0.254
password: '123456'
port: 6379

@ -19,8 +19,8 @@
</resources>
</cache-template>
<!-- hotData 热点数据它使用名为opsliDefaults的<cache-template>,并将其主键覆盖到更广泛的类型 -->
<cache alias="hotData" uses-template="opsliDefaults">
<!-- timed 时效数据它使用名为opsliDefaults的<cache-template>,并将其主键覆盖到更广泛的类型 -->
<cache alias="timed" uses-template="opsliDefaults">
<!--缓存到期配置-->
<expiry>
<!-- 只允许配秒 -->

Loading…
Cancel
Save