Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
782df98c
Commit
782df98c
authored
Jun 17, 2025
by
王祖波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加载图片缓存统计
parent
79dd95d6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
ImageCombined.java
...haoban/manage/service/context/combined/ImageCombined.java
+17
-5
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/context/combined/ImageCombined.java
View file @
782df98c
...
...
@@ -10,8 +10,10 @@ import com.gic.haoban.manage.api.qdto.combined.CombinedQDTO;
import
com.gic.haoban.manage.service.util.ApolloUtils
;
import
com.github.benmanes.caffeine.cache.Cache
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
com.github.benmanes.caffeine.cache.stats.CacheStats
;
import
net.coobird.thumbnailator.Thumbnails
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.ss.formula.functions.T
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -28,9 +30,7 @@ import java.io.InputStream;
import
java.net.URL
;
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.*
;
/**
* Created by wangzubo on 2024/10/27.
...
...
@@ -42,14 +42,15 @@ public class ImageCombined {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ImageCombined
.
class
);
private
static
final
Cache
<
String
,
BufferedImage
>
imageCache
=
Caffeine
.
newBuilder
()
.
maximumWeight
(
2
00
*
1024
*
1024
)
// 100MB
.
weigher
((
String
key
,
BufferedImage
image
)
->
image
.
getWidth
()
*
image
.
getHeight
()
*
3
)
.
maximumWeight
(
3
00
*
1024
*
1024
)
// 100MB
.
weigher
((
String
key
,
BufferedImage
image
)
->
image
.
getWidth
()
*
image
.
getHeight
()
*
4
)
.
removalListener
((
key
,
value
,
cause
)
->
{
logger
.
info
(
"移除缓存:{}"
,
key
);
if
(
value
!=
null
)
{
value
.
flush
();
}
})
.
recordStats
()
.
expireAfterAccess
(
10
,
TimeUnit
.
MINUTES
)
// 可设置失效时间
.
build
();
...
...
@@ -62,6 +63,8 @@ public class ImageCombined {
new
ThreadPoolExecutor
.
AbortPolicy
()
);
private
static
final
ScheduledExecutorService
CACHE_STAT_SCHEDULER
=
Executors
.
newScheduledThreadPool
(
1
);
private
static
void
refreshThreadPool
(
ConfigChangeEvent
changeEvent
)
{
if
(!
StringUtils
.
equals
(
changeEvent
.
getNamespace
(),
APPLICATION
))
{
return
;
...
...
@@ -99,6 +102,15 @@ public class ImageCombined {
ImageIO
.
scanForPlugins
();
// 初始化图像插件
Config
config
=
ConfigService
.
getAppConfig
();
config
.
addChangeListener
(
ImageCombined:
:
refreshThreadPool
);
CACHE_STAT_SCHEDULER
.
scheduleAtFixedRate
(()
->
{
CacheStats
stats
=
imageCache
.
stats
();
logger
.
info
(
"【加载图片缓存统计】请求数: {}, 命中: {}, 未命中: {}, 命中率: {}%"
,
stats
.
requestCount
(),
stats
.
hitCount
(),
stats
.
missCount
(),
String
.
format
(
"%.2f"
,
stats
.
hitRate
()
*
100
));
},
10
,
10
,
TimeUnit
.
MINUTES
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
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