|
@@ -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";
|
|
|
+ }
|
|
|
+
|
|
|
+}
|