Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
spring-boot-starter-dsp
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
shenjiaqing
spring-boot-starter-dsp
Commits
5fd27834
Commit
5fd27834
authored
Nov 21, 2023
by
wangwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
支持关闭缓存预热
parent
7acae66b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
7 deletions
+10
-7
build.gradle
build.gradle
+1
-1
CacheConfig.java
...com/duiba/spring/boot/starter/dsp/warmup/CacheConfig.java
+9
-6
No files found.
build.gradle
View file @
5fd27834
...
@@ -38,7 +38,7 @@ allprojects {
...
@@ -38,7 +38,7 @@ allprojects {
}
}
group
=
"cn.com.duiba.boot"
group
=
"cn.com.duiba.boot"
version
=
"0.0.
59
"
version
=
"0.0.
60-SNAPSHOT
"
}
}
subprojects
{
subprojects
{
...
...
spring-boot-starter-dsp-warmup/src/main/java/cn/com/duiba/spring/boot/starter/dsp/warmup/CacheConfig.java
View file @
5fd27834
...
@@ -57,7 +57,10 @@ public class CacheConfig implements InitializingBean {
...
@@ -57,7 +57,10 @@ public class CacheConfig implements InitializingBean {
@Value
(
"${local.cache.warmup.enable:false}"
)
@Value
(
"${local.cache.warmup.enable:false}"
)
private
Boolean
cacheEnable
;
private
Boolean
cacheEnable
;
public
void
onMainContextRefreshed
(){
public
void
onMainContextRefreshed
()
{
if
(!
cacheEnable
)
{
return
;
}
String
[]
names
=
applicationContext
.
getBeanDefinitionNames
();
String
[]
names
=
applicationContext
.
getBeanDefinitionNames
();
for
(
String
beanName
:
names
)
{
for
(
String
beanName
:
names
)
{
try
{
try
{
...
@@ -118,15 +121,15 @@ public class CacheConfig implements InitializingBean {
...
@@ -118,15 +121,15 @@ public class CacheConfig implements InitializingBean {
field
.
setAccessible
(
false
);
field
.
setAccessible
(
false
);
}
}
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
warn
(
"cache实例获取异常"
,
e
);
logger
.
warn
(
"cache实例获取异常"
,
e
);
}
}
}
}
}
}
// 顺序最靠后 等其他地方处理MainContextRefreshedEvent事件完成后
// 顺序最靠后 等其他地方处理MainContextRefreshedEvent事件完成后
public
void
onServerCache
(){
public
void
onServerCache
()
{
try
{
try
{
// 本地缓存预热开关 : 默认关闭
// 本地缓存预热开关 : 默认关闭
if
(!
cacheEnable
)
{
if
(!
cacheEnable
)
{
logger
.
warn
(
"Cache preheating failed,because cacheEnable is false"
);
logger
.
warn
(
"Cache preheating failed,because cacheEnable is false"
);
...
@@ -138,7 +141,7 @@ public class CacheConfig implements InitializingBean {
...
@@ -138,7 +141,7 @@ public class CacheConfig implements InitializingBean {
return
;
return
;
}
}
logger
.
info
(
"container of all registered AppInfo size: {}"
,
instances
.
size
());
logger
.
info
(
"container of all registered AppInfo size: {}"
,
instances
.
size
());
List
<
InstanceInfo
>
list
=
instances
.
stream
().
sorted
((
o1
,
o2
)
->
(
int
)
(
o2
.
getLeaseInfo
().
getServiceUpTimestamp
()
-
o1
.
getLeaseInfo
().
getServiceUpTimestamp
())).
collect
(
Collectors
.
toList
());
List
<
InstanceInfo
>
list
=
instances
.
stream
().
sorted
((
o1
,
o2
)
->
(
int
)
(
o2
.
getLeaseInfo
().
getServiceUpTimestamp
()
-
o1
.
getLeaseInfo
().
getServiceUpTimestamp
())).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isEmpty
(
list
))
{
if
(
CollectionUtils
.
isEmpty
(
list
))
{
logger
.
warn
(
"Cache preheating failed,because 服务启动获取【"
+
appName
+
"】列表信息为空"
);
logger
.
warn
(
"Cache preheating failed,because 服务启动获取【"
+
appName
+
"】列表信息为空"
);
return
;
return
;
...
@@ -217,7 +220,7 @@ public class CacheConfig implements InitializingBean {
...
@@ -217,7 +220,7 @@ public class CacheConfig implements InitializingBean {
}
}
});
});
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
warn
(
"服务启动获取【"
+
appName
+
"】列表信息失败"
,
e
);
logger
.
warn
(
"服务启动获取【"
+
appName
+
"】列表信息失败"
,
e
);
}
}
}
}
...
...
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