Skip to content

Commit 0bf8e0d

Browse files
committed
add guava cache manager
1 parent f3d570b commit 0bf8e0d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

platform-api/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
<artifactId>gson</artifactId>
6666
</dependency>
6767

68+
<dependency>
69+
<groupId>org.springframework</groupId>
70+
<artifactId>spring-context-support</artifactId>
71+
</dependency>
72+
6873
<dependency>
6974
<groupId>org.hibernate</groupId>
7075
<artifactId>hibernate-validator</artifactId>

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
package com.flow.platform.api.config;
1818

19+
import com.google.common.cache.CacheBuilder;
20+
import java.util.concurrent.TimeUnit;
1921
import org.springframework.cache.CacheManager;
2022
import org.springframework.cache.annotation.EnableCaching;
21-
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
23+
import org.springframework.cache.guava.GuavaCacheManager;
2224
import org.springframework.context.annotation.Bean;
2325
import org.springframework.context.annotation.Configuration;
2426

@@ -29,8 +31,21 @@
2931
@EnableCaching
3032
public class CachingConfig {
3133

34+
private final static int EXPIRE_CACHE_SECOND = 3600 * 24;
35+
36+
private final static int MAX_CACHE_NUM = 1000;
37+
38+
39+
private CacheBuilder cacheBuilder = CacheBuilder
40+
.newBuilder()
41+
.expireAfterAccess(EXPIRE_CACHE_SECOND, TimeUnit.SECONDS)
42+
.maximumSize(MAX_CACHE_NUM);
43+
44+
3245
@Bean
3346
public CacheManager cacheManager() {
34-
return new ConcurrentMapCacheManager();
47+
GuavaCacheManager guavaCacheManager = new GuavaCacheManager();
48+
guavaCacheManager.setCacheBuilder(cacheBuilder);
49+
return guavaCacheManager;
3550
}
3651
}

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<javax.mail.version>1.5.5</javax.mail.version>
5858
<yamlbeans.version>1.12</yamlbeans.version>
5959
<velocity.version>1.5</velocity.version>
60+
<spring-context-support.version>4.3.8.RELEASE</spring-context-support.version>
6061
</properties>
6162

6263
<build>
@@ -94,6 +95,13 @@
9495

9596
<dependencyManagement>
9697
<dependencies>
98+
99+
<dependency>
100+
<groupId>org.springframework</groupId>
101+
<artifactId>spring-context-support</artifactId>
102+
<version>${spring-context-support.version}</version>
103+
</dependency>
104+
97105
<dependency>
98106
<groupId>javax.mail</groupId>
99107
<artifactId>javax.mail-api</artifactId>

0 commit comments

Comments
 (0)