Skip to content

Commit

Permalink
加入jetcache缓存,提高权限判断的性能
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoutaoo committed Nov 8, 2019
1 parent e019ba3 commit 584c024
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions auth/authentication-server/pom.xml
Expand Up @@ -37,6 +37,11 @@
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
<!--jetcache缓存 -->
<dependency>
<groupId>com.alicp.jetcache</groupId>
<artifactId>jetcache-starter-redis</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
@@ -1,5 +1,6 @@
package com.springboot.cloud.auth.authentication;

import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
Expand All @@ -8,6 +9,7 @@
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableCreateCacheAnnotation
public class Oauth2AuthenticationApplication {
public static void main(String[] args) {
SpringApplication.run(Oauth2AuthenticationApplication.class, args);
Expand Down
@@ -1,9 +1,11 @@
package com.springboot.cloud.auth.authentication.service.impl;

import com.springboot.cloud.auth.authentication.service.IResourceService;
import com.springboot.cloud.sysadmin.organization.entity.po.Resource;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.springboot.cloud.auth.authentication.provider.ResourceProvider;
import com.springboot.cloud.auth.authentication.service.IResourceService;
import com.springboot.cloud.auth.authentication.service.NewMvcRequestMatcher;
import com.springboot.cloud.sysadmin.organization.entity.po.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.ConfigAttribute;
Expand Down Expand Up @@ -71,6 +73,7 @@ public ConfigAttribute findConfigAttributesByUrl(HttpServletRequest authRequest)
}

@Override
@Cached(name = "resource4user::", key = "#username", cacheType = CacheType.BOTH)
public Set<Resource> queryByUsername(String username) {
return resourceProvider.resources(username).getData();
}
Expand Down
27 changes: 27 additions & 0 deletions auth/authentication-server/src/main/resources/application.yml
Expand Up @@ -34,6 +34,33 @@ feign:
okhttp:
enabled: true


jetcache:
statIntervalMinutes: 15
areaInCacheName: false
hidePackages: com.springboot.cloud
local:
# 短時本地緩存,主要用于要求时效较高的配置
default:
type: caffeine
keyConvertor: fastjson
expireAfterWriteInMillis: 60000
expireAfterAccessInMillis: 40000
remote:
# 默认2分钟的远程缓存
default:
type: redis
expireAfterWriteInMillis: 120000
keyConvertor: fastjson
valueEncoder: kryo
valueDecoder: kryo
poolConfig:
minIdle: 5
maxIdle: 20
maxTotal: 50
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}

logging:
level:
com.springboot.cloud: debug
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -57,6 +57,12 @@
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!--jetcache缓存 -->
<dependency>
<groupId>com.alicp.jetcache</groupId>
<artifactId>jetcache-starter-redis</artifactId>
<version>2.5.14</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 584c024

Please sign in to comment.