|
@@ -1,7 +1,11 @@
|
|
|
package cn.com.qmth.examcloud.support.cache;
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.assertj.core.util.Arrays;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.AppCacheBean;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
|
|
|
+import cn.com.qmth.examcloud.web.cache.ObjectRedisCacheTrigger;
|
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
|
|
@@ -9,7 +13,7 @@ public class CacheHelper {
|
|
|
|
|
|
private static RedisClient redisClient;
|
|
|
|
|
|
- private static CacheObjectTrigger cacheObjectTrigger;
|
|
|
+ private static ObjectRedisCacheTrigger objectRedisCacheTrigger;
|
|
|
|
|
|
private static RedisClient getRedisClient() {
|
|
|
if (null == redisClient) {
|
|
@@ -18,13 +22,44 @@ public class CacheHelper {
|
|
|
return redisClient;
|
|
|
}
|
|
|
|
|
|
- private static CacheObjectTrigger getCacheObjectTrigger() {
|
|
|
- if (null == cacheObjectTrigger) {
|
|
|
- cacheObjectTrigger = SpringContextHolder.getBean(CacheObjectTrigger.class);
|
|
|
+ private static ObjectRedisCacheTrigger getObjectRedisCacheTrigger() {
|
|
|
+ if (null == objectRedisCacheTrigger) {
|
|
|
+ objectRedisCacheTrigger = SpringContextHolder.getBean(ObjectRedisCacheTrigger.class);
|
|
|
}
|
|
|
- return cacheObjectTrigger;
|
|
|
+ return objectRedisCacheTrigger;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 加载并获取缓存对象
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param keyPrefix
|
|
|
+ * @param propKeys
|
|
|
+ * @param c
|
|
|
+ * @param appName
|
|
|
+ * @param className
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static <T> T get(String keyPrefix, Object[] propKeys, Class<T> c, String appName,
|
|
|
+ String className) {
|
|
|
+
|
|
|
+ String key = keyPrefix + StringUtils.join(Arrays.asList(propKeys), '_');
|
|
|
+
|
|
|
+ T t = getRedisClient().get(key, c);
|
|
|
+ if (null == t) {
|
|
|
+ getObjectRedisCacheTrigger().fire(appName, className, propKeys);
|
|
|
+ t = getRedisClient().get(key, c);
|
|
|
+ }
|
|
|
+ return t;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取APP
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param appId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
public static AppCacheBean getApp(Long appId) {
|
|
|
String key = "$_APP:" + appId;
|
|
|
return getRedisClient().get(key, AppCacheBean.class);
|
|
@@ -38,15 +73,9 @@ public class CacheHelper {
|
|
|
* @return
|
|
|
*/
|
|
|
public static SysPropertyCacheBean getSysProperty(String propKey) {
|
|
|
- String key = "$_SYS_PROP:" + propKey;
|
|
|
- SysPropertyCacheBean sysPropertyCacheBean = getRedisClient().get(key,
|
|
|
- SysPropertyCacheBean.class);
|
|
|
- if (null == sysPropertyCacheBean) {
|
|
|
- // redis未缓存时,调用触发器
|
|
|
- getCacheObjectTrigger().loadSysProperty(propKey);
|
|
|
- sysPropertyCacheBean = getRedisClient().get(key, SysPropertyCacheBean.class);
|
|
|
- }
|
|
|
- return sysPropertyCacheBean;
|
|
|
+ return get("$_SYS_PROP:", new String[]{propKey}, SysPropertyCacheBean.class,
|
|
|
+ "EC-CORE-BASIC",
|
|
|
+ "cn.com.qmth.examcloud.core.basic.service.cache.SystemPropertyCache");
|
|
|
}
|
|
|
|
|
|
}
|