Skip to content

Commit 1169248

Browse files
committed
cache
1 parent 75ffb43 commit 1169248

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2017 flow.ci
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.flow.platform.api.config;
18+
19+
import org.springframework.cache.CacheManager;
20+
import org.springframework.cache.annotation.EnableCaching;
21+
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
22+
import org.springframework.context.annotation.Bean;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
/**
26+
* @author yh@firim
27+
*/
28+
@Configuration
29+
@EnableCaching
30+
public class CachingConfig {
31+
32+
@Bean
33+
public CacheManager cacheManager() {
34+
return new ConcurrentMapCacheManager();
35+
}
36+
}

platform-api/src/main/java/com/flow/platform/api/config/WebConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"com.flow.platform.api.util",
6565
"com.flow.platform.api.consumer",
6666
"com.flow.platform.api.initializers"})
67-
@Import({AppConfig.class})
67+
@Import({AppConfig.class, CachingConfig.class})
6868
public class WebConfig extends WebMvcConfigurerAdapter {
6969

7070
private final static Gson GSON_CONFIG_FOR_RESPONE = new GsonBuilder()

platform-api/src/main/java/com/flow/platform/api/service/GitServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import org.eclipse.jgit.lib.ProgressMonitor;
4646
import org.eclipse.jgit.lib.Ref;
4747
import org.springframework.beans.factory.annotation.Autowired;
48+
import org.springframework.cache.CacheManager;
49+
import org.springframework.cache.annotation.Cacheable;
4850
import org.springframework.stereotype.Service;
4951

5052
/**
@@ -57,6 +59,9 @@ public class GitServiceImpl implements GitService {
5759

5860
private final Map<GitSource, Class<? extends GitClientBuilder>> clientBuilderType = new HashMap<>(6);
5961

62+
@Autowired
63+
private CacheManager cacheManager;
64+
6065
@Autowired
6166
private Path workspace;
6267

@@ -86,6 +91,7 @@ public String clone(Node node, String filePath, ProgressListener progressListene
8691
}
8792

8893
@Override
94+
@Cacheable(value = "branches")
8995
public List<String> branches(Node node) {
9096
checkRequiredEnv(node);
9197
GitClient client = gitClientInstance(node);

0 commit comments

Comments
 (0)