WANG %!s(int64=6) %!d(string=hai) anos
pai
achega
796b8a378a

+ 1 - 1
src/main/java/cn/com/qmth/examcloud/web/cache/CacheCloudServiceProvider.java

@@ -35,7 +35,7 @@ public class CacheCloudServiceProvider implements CloudService {
 	private static Map<String, ObjectCache<?>> map = Maps.newConcurrentMap();
 
 	@RequestMapping(value = "refresh", method = RequestMethod.POST)
-	public String post(@RequestBody RefreshCacheReq req) {
+	public String refresh(@RequestBody RefreshCacheReq req) {
 
 		String className = req.getClassName();
 		Object[] keys = req.getKeys();

+ 76 - 0
src/main/java/cn/com/qmth/examcloud/web/cache/ObjectRedisCacheTrigger.java

@@ -0,0 +1,76 @@
+package cn.com.qmth.examcloud.web.cache;
+
+import java.util.Map;
+
+import org.springframework.stereotype.Component;
+
+import com.google.common.collect.Maps;
+
+import cn.com.qmth.examcloud.web.cloud.CloudClientSupport;
+import cn.com.qmth.examcloud.web.support.SpringContextHolder;
+
+/**
+ * redis缓存触发器
+ *
+ * @author WANGWEI
+ * @date 2019年5月9日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Component
+public class ObjectRedisCacheTrigger extends CloudClientSupport {
+
+	private static Map<String, Boolean> hasClassMap = Maps.newConcurrentMap();
+
+	private static Map<String, ObjectCache<?>> objectCacheMap = Maps.newConcurrentMap();
+
+	/**
+	 * 开火
+	 *
+	 * @author WANGWEI
+	 * @param appName
+	 * @param keys
+	 * @return
+	 */
+	public void fire(String appName, String className, Object... keys) {
+
+		Boolean has = hasClassMap.get(className);
+		ObjectCache<?> objectCache = null;
+
+		if (null != has) {
+			if (has) {
+				objectCache = objectCacheMap.get(className);
+				objectCache.refresh(keys);
+				return;
+			}
+		} else {
+			try {
+				Class<?> c = Class.forName(className);
+				objectCache = (ObjectCache<?>) SpringContextHolder.getBean(c);
+				objectCache.refresh(keys);
+				objectCacheMap.put(className, objectCache);
+				hasClassMap.put(className, true);
+				return;
+			} catch (ClassNotFoundException e) {
+				hasClassMap.put(className, false);
+			}
+		}
+
+		String[] keyArray = new String[keys.length];
+
+		for (int i = 0; i < keys.length; i++) {
+			keyArray[i] = String.valueOf(keys[i]);
+		}
+
+		RefreshCacheReq req = new RefreshCacheReq();
+		req.setClassName(className);
+		req.setKeys(keyArray);
+		post(appName, "refresh", req);
+
+	}
+
+	@Override
+	protected String getRequestMappingPrefix() {
+		return "cache";
+	}
+
+}