wangwei há 5 anos atrás
pai
commit
9b59f82dda

+ 36 - 5
src/main/java/cn/com/qmth/examcloud/web/cache/RandomCacheVersionHelper.java

@@ -1,5 +1,12 @@
 package cn.com.qmth.examcloud.web.cache;
 
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import cn.com.qmth.examcloud.web.redis.RedisClient;
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
+
 /**
  * 随机缓存版本控制
  *
@@ -8,20 +15,44 @@ package cn.com.qmth.examcloud.web.cache;
  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
  */
 public class RandomCacheVersionHelper {
-	
-	
+
+	private static RedisClient redisClient;
+
+	private static Map<Class<? extends RandomCacheBean>, String> presentMap = Maps.newHashMap();
+
+	private static Map<Class<? extends RandomCacheBean>, String> timeoutMap = Maps.newHashMap();
+
+	private static RedisClient getRedisClient() {
+		if (null == redisClient) {
+			redisClient = SpringContextHolder.getBean(RedisClient.class);
+		}
+		return redisClient;
+	}
 
 	/**
 	 * 设置版本
 	 *
 	 * @author WANGWEI
 	 * @param c
-	 * @param propKeys
 	 * @param version
+	 * @param timeout
 	 */
-	public static void setVersion(Class<? extends RandomCacheBean> c, Object[] propKeys,
-			String version) {
+	public static void setVersion(Class<? extends RandomCacheBean> c, String version, int timeout) {
+		String key = "$_V_" + c.getCanonicalName();
+		getRedisClient().set(key, version, timeout);
+	}
 
+	/**
+	 * 获取版本
+	 *
+	 * @author WANGWEI
+	 * @param c
+	 * @param version
+	 * @return
+	 */
+	public static String getVersion(Class<? extends RandomCacheBean> c, String version) {
+		String key = "$_V_" + c.getCanonicalName();
+		return getRedisClient().get(key, String.class);
 	}
 
 }