Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6ca29c0d
authored
Jan 22, 2018
by
xuxueli
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
报表缓存Key优化,支持以时间为粒度缓存;
LocalCache优化,避免缓存堆积;
parent
a1e11ea1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/LocalCacheUtil.java
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/LocalCacheUtil.java
View file @
6ca29c0d
...
@@ -61,6 +61,11 @@ public class LocalCacheUtil {
...
@@ -61,6 +61,11 @@ public class LocalCacheUtil {
* @return
* @return
*/
*/
public
static
boolean
set
(
String
key
,
Object
val
,
long
cacheTime
){
public
static
boolean
set
(
String
key
,
Object
val
,
long
cacheTime
){
// clean timeout cache, before set new cache (avoid cache too much)
cleanTimeutCache
();
// set new cache
if
(
StringUtils
.
isBlank
(
key
))
{
if
(
StringUtils
.
isBlank
(
key
))
{
return
false
;
return
false
;
}
}
...
@@ -109,4 +114,21 @@ public class LocalCacheUtil {
...
@@ -109,4 +114,21 @@ public class LocalCacheUtil {
}
}
}
}
/**
* clean timeout cache
*
* @return
*/
public
static
boolean
cleanTimeutCache
(){
if
(!
cacheRepository
.
keySet
().
isEmpty
())
{
for
(
String
key:
cacheRepository
.
keySet
())
{
LocalCacheData
localCacheData
=
cacheRepository
.
get
(
key
);
if
(
localCacheData
!=
null
&&
System
.
currentTimeMillis
()>=
localCacheData
.
getTimeoutTime
())
{
cacheRepository
.
remove
(
key
);
}
}
}
return
true
;
}
}
}
xxl-job-admin/src/main/java/com/xxl/job/admin/service/impl/XxlJobServiceImpl.java
View file @
6ca29c0d
...
@@ -325,7 +325,8 @@ public class XxlJobServiceImpl implements XxlJobService {
...
@@ -325,7 +325,8 @@ public class XxlJobServiceImpl implements XxlJobService {
@Override
@Override
public
ReturnT
<
Map
<
String
,
Object
>>
triggerChartDate
(
Date
startDate
,
Date
endDate
)
{
public
ReturnT
<
Map
<
String
,
Object
>>
triggerChartDate
(
Date
startDate
,
Date
endDate
)
{
// get cache
// get cache
Map
<
String
,
Object
>
triggerChartDateCache
=
(
Map
<
String
,
Object
>)
LocalCacheUtil
.
get
(
TRIGGER_CHART_DATA_CACHE
);
String
cacheKey
=
TRIGGER_CHART_DATA_CACHE
+
"_"
+
startDate
.
getTime
()
+
"_"
+
endDate
.
getTime
();
Map
<
String
,
Object
>
triggerChartDateCache
=
(
Map
<
String
,
Object
>)
LocalCacheUtil
.
get
(
cacheKey
);
if
(
triggerChartDateCache
!=
null
)
{
if
(
triggerChartDateCache
!=
null
)
{
return
new
ReturnT
<
Map
<
String
,
Object
>>(
triggerChartDateCache
);
return
new
ReturnT
<
Map
<
String
,
Object
>>(
triggerChartDateCache
);
}
}
...
@@ -376,7 +377,7 @@ public class XxlJobServiceImpl implements XxlJobService {
...
@@ -376,7 +377,7 @@ public class XxlJobServiceImpl implements XxlJobService {
result
.
put
(
"triggerCountFailTotal"
,
triggerCountFailTotal
);
result
.
put
(
"triggerCountFailTotal"
,
triggerCountFailTotal
);
// set cache
// set cache
LocalCacheUtil
.
set
(
TRIGGER_CHART_DATA_CACHE
,
result
,
60
*
1000
);
// cache 60s
LocalCacheUtil
.
set
(
cacheKey
,
result
,
60
*
1000
);
// cache 60s
return
new
ReturnT
<
Map
<
String
,
Object
>>(
result
);
return
new
ReturnT
<
Map
<
String
,
Object
>>(
result
);
}
}
...
...
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