Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 584c024

Browse files
committed
加入jetcache缓存,提高权限判断的性能
1 parent e019ba3 commit 584c024

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

‎auth/authentication-server/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
<groupId>io.springfox</groupId>
3838
<artifactId>springfox-swagger-ui</artifactId>
3939
</dependency>
40+
<!--jetcache缓存 -->
41+
<dependency>
42+
<groupId>com.alicp.jetcache</groupId>
43+
<artifactId>jetcache-starter-redis</artifactId>
44+
</dependency>
4045
</dependencies>
4146

4247
<build>

‎auth/authentication-server/src/main/java/com/springboot/cloud/auth/authentication/Oauth2AuthenticationApplication.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.springboot.cloud.auth.authentication;
22

3+
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@@ -8,6 +9,7 @@
89
@SpringBootApplication
910
@EnableDiscoveryClient
1011
@EnableFeignClients
12+
@EnableCreateCacheAnnotation
1113
public class Oauth2AuthenticationApplication {
1214
public static void main(String[] args) {
1315
SpringApplication.run(Oauth2AuthenticationApplication.class, args);

‎auth/authentication-server/src/main/java/com/springboot/cloud/auth/authentication/service/impl/ResourceService.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.springboot.cloud.auth.authentication.service.impl;
22

3-
import com.springboot.cloud.auth.authentication.service.IResourceService;
4-
import com.springboot.cloud.sysadmin.organization.entity.po.Resource;
3+
import com.alicp.jetcache.anno.CacheType;
4+
import com.alicp.jetcache.anno.Cached;
55
import com.springboot.cloud.auth.authentication.provider.ResourceProvider;
6+
import com.springboot.cloud.auth.authentication.service.IResourceService;
67
import com.springboot.cloud.auth.authentication.service.NewMvcRequestMatcher;
8+
import com.springboot.cloud.sysadmin.organization.entity.po.Resource;
79
import lombok.extern.slf4j.Slf4j;
810
import org.springframework.beans.factory.annotation.Autowired;
911
import org.springframework.security.access.ConfigAttribute;
@@ -71,6 +73,7 @@ public ConfigAttribute findConfigAttributesByUrl(HttpServletRequest authRequest)
7173
}
7274

7375
@Override
76+
@Cached(name = "resource4user::", key = "#username", cacheType = CacheType.BOTH)
7477
public Set<Resource> queryByUsername(String username) {
7578
return resourceProvider.resources(username).getData();
7679
}

‎auth/authentication-server/src/main/resources/application.yml‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ feign:
3434
okhttp:
3535
enabled: true
3636

37+
38+
jetcache:
39+
statIntervalMinutes: 15
40+
areaInCacheName: false
41+
hidePackages: com.springboot.cloud
42+
local:
43+
# 短時本地緩存,主要用于要求时效较高的配置
44+
default:
45+
type: caffeine
46+
keyConvertor: fastjson
47+
expireAfterWriteInMillis: 60000
48+
expireAfterAccessInMillis: 40000
49+
remote:
50+
# 默认2分钟的远程缓存
51+
default:
52+
type: redis
53+
expireAfterWriteInMillis: 120000
54+
keyConvertor: fastjson
55+
valueEncoder: kryo
56+
valueDecoder: kryo
57+
poolConfig:
58+
minIdle: 5
59+
maxIdle: 20
60+
maxTotal: 50
61+
host: ${REDIS_HOST:localhost}
62+
port: ${REDIS_PORT:6379}
63+
3764
logging:
3865
level:
3966
com.springboot.cloud: debug

‎pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
<artifactId>springfox-swagger-ui</artifactId>
5858
<version>2.9.2</version>
5959
</dependency>
60+
<!--jetcache缓存 -->
61+
<dependency>
62+
<groupId>com.alicp.jetcache</groupId>
63+
<artifactId>jetcache-starter-redis</artifactId>
64+
<version>2.5.14</version>
65+
</dependency>
6066
</dependencies>
6167
</dependencyManagement>
6268

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /