WANG 6 years ago
parent
commit
81985ad7d0

+ 17 - 1
src/main/java/cn/com/qmth/examcloud/support/cache/CacheHelper.java

@@ -9,6 +9,8 @@ public class CacheHelper {
 
 	private static RedisClient redisClient;
 
+	private static CacheObjectTrigger cacheObjectTrigger;
+
 	private static RedisClient getRedisClient() {
 		if (null == redisClient) {
 			redisClient = SpringContextHolder.getBean(RedisClient.class);
@@ -16,6 +18,13 @@ public class CacheHelper {
 		return redisClient;
 	}
 
+	private static CacheObjectTrigger getCacheObjectTrigger() {
+		if (null == cacheObjectTrigger) {
+			cacheObjectTrigger = SpringContextHolder.getBean(CacheObjectTrigger.class);
+		}
+		return cacheObjectTrigger;
+	}
+
 	public static AppCacheBean getApp(Long appId) {
 		String key = "$_APP:" + appId;
 		return getRedisClient().get(key, AppCacheBean.class);
@@ -23,7 +32,14 @@ public class CacheHelper {
 
 	public static SysPropertyCacheBean getSysProperty(String propKey) {
 		String key = "$_SYS_PROP:" + propKey;
-		return getRedisClient().get(key, SysPropertyCacheBean.class);
+		SysPropertyCacheBean sysPropertyCacheBean = getRedisClient().get(key,
+				SysPropertyCacheBean.class);
+		if (null == sysPropertyCacheBean) {
+			getCacheObjectTrigger().loadSysProperty(propKey);
+			sysPropertyCacheBean = getRedisClient().get(key, SysPropertyCacheBean.class);
+		}
+
+		return sysPropertyCacheBean;
 	}
 
 }

+ 15 - 0
src/main/java/cn/com/qmth/examcloud/support/cache/CacheObjectTrigger.java

@@ -0,0 +1,15 @@
+package cn.com.qmth.examcloud.support.cache;
+
+/**
+ * 缓存对象触发器
+ *
+ * @author WANGWEI
+ * @date 2019年5月8日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface CacheObjectTrigger {
+
+	default void loadSysProperty(String propKey) {
+	};
+
+}