kezhenxu94 commented on a change in pull request #6974:
URL: https://github.com/apache/dolphinscheduler/pull/6974#discussion_r756606649



##########
File path: 
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/cache/impl/QueueCacheProxyImpl.java
##########
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.service.cache.impl;
+
+import org.apache.dolphinscheduler.common.utils.JSONUtils;
+import org.apache.dolphinscheduler.dao.entity.Queue;
+import org.apache.dolphinscheduler.service.bean.SpringApplicationContext;
+import org.apache.dolphinscheduler.service.cache.QueueCacheProxy;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Component;
+
+@Component
+@CacheConfig(cacheResolver = "cacheResolver", cacheNames = "user")
+public class QueueCacheProxyImpl implements QueueCacheProxy {
+
+    private final Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Override
+    @CacheEvict(cacheNames = "user", allEntries = true)
+    public void expireAllUserCache() {
+        // just evict cache
+        logger.debug("expire all user cache");
+    }
+
+    @Override
+    public void cacheExpire(Class updateObjClass, String updateObjJson) {
+        Queue updateQueue = (Queue) JSONUtils.parseObject(updateObjJson, 
updateObjClass);
+        if (updateQueue == null) {
+            return;
+        }
+        
SpringApplicationContext.getBean(QueueCacheProxy.class).expireAllUserCache();

Review comment:
       Why not use `@AutoWired`?

##########
File path: dolphinscheduler-service/src/main/resources/cache.properties
##########
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+cache.enable=false
+cache.tenant.expire=1
+cache.tenant.max.size=100
+cache.user.expire=1
+cache.user.max.size=100

Review comment:
       Consider using the standard cache configuration of Spring Boot so that 
users can change to other cache implementation easily

##########
File path: tools/dependencies/known-dependencies.txt
##########
@@ -16,7 +16,9 @@ avro-1.7.4.jar
 aws-java-sdk-1.7.4.jar
 bonecp-0.8.0.RELEASE.jar
 byte-buddy-1.9.16.jar
+caffeine-2.9.2.jar

Review comment:
       You cannot simply modify this file without changes to the LICENSE file

##########
File path: 
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/cache/config/MultiCacheManager.java
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.service.cache.config;
+
+import java.util.concurrent.TimeUnit;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.CachingConfigurerSupport;
+import org.springframework.cache.caffeine.CaffeineCacheManager;
+import org.springframework.cache.interceptor.CacheResolver;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import com.github.benmanes.caffeine.cache.Caffeine;
+
+/**
+ * multi cache manager
+ */
+@Configuration
+public class MultiCacheManager extends CachingConfigurerSupport {
+
+    @Autowired
+    private CacheConfig cacheConfig;
+
+    /**
+     * cache manager for tenant
+     */
+    @Bean
+    public CacheManager tenantCacheManager() {
+        if (!cacheConfig.isCacheEnable()) {
+            return null;
+        }
+        CaffeineCacheManager cacheManager = new CaffeineCacheManager();
+        cacheManager.setCaffeine(Caffeine.newBuilder()
+                .expireAfterWrite(cacheConfig.getTenantExpire(), 
TimeUnit.MINUTES)
+                .maximumSize(cacheConfig.getTenantMaxSize()));
+        return cacheManager;
+    }
+
+    /**
+     * cache manager for user
+     */
+    @Bean
+    public CacheManager userCacheManager() {
+        if (!cacheConfig.isCacheEnable()) {
+            return null;
+        }
+        CaffeineCacheManager cacheManager = new CaffeineCacheManager();
+        cacheManager.setCaffeine(Caffeine.newBuilder()
+                .expireAfterWrite(cacheConfig.getUserExpire(), 
TimeUnit.MINUTES)
+                .maximumSize(cacheConfig.getUserMaxSize()));
+        return cacheManager;
+    }
+
+    /**
+     * cache resolver
+     */
+    @Bean
+    public CacheResolver cacheResolver() {

Review comment:
       `@Override` is missing

##########
File path: 
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/cache/config/CacheConfig.java
##########
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dolphinscheduler.service.cache.config;
+
+import org.apache.dolphinscheduler.common.utils.PropertyUtils;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * cache config
+ */
+@Component
+public class CacheConfig {

Review comment:
       Why not use the standard cache configuration of Spring Boot?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to