|
@@ -1,14 +1,8 @@
|
|
|
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.cache.RandomCacheBean;
|
|
|
-import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
+import cn.com.qmth.examcloud.web.cache.ObjectRedisCacheProcessor;
|
|
|
|
|
|
/**
|
|
|
* 所有缓存对象从此类获取
|
|
@@ -19,50 +13,6 @@ import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
*/
|
|
|
public class CacheHelper {
|
|
|
|
|
|
- private static RedisClient redisClient;
|
|
|
-
|
|
|
- private static ObjectRedisCacheTrigger objectRedisCacheTrigger;
|
|
|
-
|
|
|
- private static RedisClient getRedisClient() {
|
|
|
- if (null == redisClient) {
|
|
|
- redisClient = SpringContextHolder.getBean(RedisClient.class);
|
|
|
- }
|
|
|
- return redisClient;
|
|
|
- }
|
|
|
-
|
|
|
- private static ObjectRedisCacheTrigger getObjectRedisCacheTrigger() {
|
|
|
- if (null == objectRedisCacheTrigger) {
|
|
|
- objectRedisCacheTrigger = SpringContextHolder.getBean(ObjectRedisCacheTrigger.class);
|
|
|
- }
|
|
|
- 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<? extends RandomCacheBean> c, String appName, String className) {
|
|
|
-
|
|
|
- String key = keyPrefix + StringUtils.join(Arrays.asList(propKeys), '_');
|
|
|
-
|
|
|
- RandomCacheBean t = getRedisClient().get(key, c);
|
|
|
- if (null == t) {
|
|
|
- getObjectRedisCacheTrigger().fire(appName, className, propKeys);
|
|
|
- t = getRedisClient().get(key, c);
|
|
|
- }
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- T ret = (T) t;
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取APP
|
|
|
*
|
|
@@ -71,8 +21,7 @@ public class CacheHelper {
|
|
|
* @return
|
|
|
*/
|
|
|
public static AppCacheBean getApp(Long appId) {
|
|
|
- String key = "$_APP:" + appId;
|
|
|
- return getRedisClient().get(key, AppCacheBean.class);
|
|
|
+ return ObjectRedisCacheProcessor.get("$_APP:", new Object[]{appId}, AppCacheBean.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -83,8 +32,8 @@ public class CacheHelper {
|
|
|
* @return
|
|
|
*/
|
|
|
public static SysPropertyCacheBean getSysProperty(String propKey) {
|
|
|
- return get("$_SYS_PROP:", new String[]{propKey}, SysPropertyCacheBean.class,
|
|
|
- "EC-CORE-BASIC",
|
|
|
+ return ObjectRedisCacheProcessor.get("$_SYS_PROP:", new Object[]{propKey},
|
|
|
+ SysPropertyCacheBean.class, "EC-CORE-BASIC",
|
|
|
"cn.com.qmth.examcloud.core.basic.service.cache.SystemPropertyCache");
|
|
|
}
|
|
|
|