Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
7336975b
Commit
7336975b
authored
Jul 29, 2021
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
local cache
parent
87da0782
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
1 deletion
+53
-1
pom.xml
community-service/pom.xml
+10
-0
CacheConfig.java
...src/main/java/com/tanpu/community/config/CacheConfig.java
+12
-1
FileController.java
...n/java/com/tanpu/community/controller/FileController.java
+12
-0
FileManager.java
...rc/main/java/com/tanpu/community/manager/FileManager.java
+7
-0
pom.xml
pom.xml
+12
-0
No files found.
community-service/pom.xml
View file @
7336975b
...
...
@@ -65,6 +65,16 @@
<artifactId>
spring-cloud-starter-zipkin
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-cache
</artifactId>
</dependency>
<dependency>
<groupId>
com.github.ben-manes.caffeine
</groupId>
<artifactId>
caffeine
</artifactId>
</dependency>
<!-- mybatis-plus自动生成所需包-->
<dependency>
<groupId>
org.apache.velocity
</groupId>
...
...
community-service/src/main/java/com/tanpu/community/config/CacheConfig.java
View file @
7336975b
...
...
@@ -3,10 +3,13 @@ package com.tanpu.community.config;
import
com.tanpu.community.cache.RedisCache
;
import
com.tanpu.community.util.SpringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.caffeine.CaffeineCacheManager
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.annotation.Resource
;
import
java.util.Arrays
;
@Configuration
public
class
CacheConfig
{
...
...
@@ -16,6 +19,14 @@ public class CacheConfig {
@Bean
public
RedisCache
redisCache
()
{
return
new
RedisCache
.
Builder
().
cacheName
(
"community2"
).
build
();
return
new
RedisCache
.
Builder
().
cacheName
(
"redis"
).
build
();
}
@Bean
public
CacheManager
cacheManager
()
{
CaffeineCacheManager
cacheManager
=
new
CaffeineCacheManager
();
cacheManager
.
setCacheNames
(
Arrays
.
asList
(
"local"
));
cacheManager
.
setCacheSpecification
(
"maximumSize=10,expireAfterWrite=10s"
);
return
cacheManager
;
}
}
community-service/src/main/java/com/tanpu/community/controller/FileController.java
View file @
7336975b
...
...
@@ -21,4 +21,16 @@ public class FileController {
public
CommonResp
<
FileUploadResp
>
uploadToRemote
(
@RequestParam
(
value
=
"file"
)
MultipartFile
file
)
{
return
CommonResp
.
success
(
fileManager
.
uploadFile
(
file
));
}
@GetMapping
(
"/test"
)
public
String
test
()
{
for
(
int
i
=
0
;
i
<
30
;
i
++)
{
System
.
out
.
println
(
fileManager
.
getId
(
""
+
i
/
2
));
}
for
(
int
i
=
30
;
i
>
0
;
i
--)
{
System
.
out
.
println
(
fileManager
.
getId
(
""
+
i
/
2
));
}
return
""
;
}
}
community-service/src/main/java/com/tanpu/community/manager/FileManager.java
View file @
7336975b
...
...
@@ -8,6 +8,7 @@ import com.tanpu.community.service.OSSFileService;
import
com.tanpu.community.util.ConvertUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -49,4 +50,10 @@ public class FileManager {
return
ossFileService
.
queryByIds
(
fileIds
).
stream
()
.
collect
(
Collectors
.
toMap
(
FileRecordEntity:
:
getFileId
,
FileRecordEntity:
:
getUrl
));
}
@Cacheable
(
value
=
"local"
,
key
=
"#id"
)
public
String
getId
(
String
id
)
{
System
.
out
.
println
(
"cache "
+
id
);
return
"haha "
+
id
;
}
}
pom.xml
View file @
7336975b
...
...
@@ -128,6 +128,18 @@
<version>
2.4.5
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-cache
</artifactId>
<version>
${spring.boot.version}
</version>
</dependency>
<dependency>
<groupId>
com.github.ben-manes.caffeine
</groupId>
<artifactId>
caffeine
</artifactId>
<version>
2.7.0
</version>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-boot-starter
</artifactId>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment