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
30e71043
Commit
30e71043
authored
Jul 29, 2021
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add log for local cache in feignservice
parent
5fce0cce
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
10 deletions
+22
-10
LocalCache.java
...e/src/main/java/com/tanpu/community/cache/LocalCache.java
+4
-0
BatchFeignCallService.java
...va/com/tanpu/community/service/BatchFeignCallService.java
+2
-1
FeignService.java
...c/main/java/com/tanpu/community/service/FeignService.java
+16
-9
No files found.
community-service/src/main/java/com/tanpu/community/cache/LocalCache.java
View file @
30e71043
...
...
@@ -32,6 +32,10 @@ public class LocalCache {
return
localCache
.
get
(
key
,
clz
);
}
public
<
T
>
void
putObject
(
String
key
,
T
value
)
{
localCache
.
put
(
key
,
value
);
}
public
<
T
>
T
getObject
(
String
key
,
Supplier
<
T
>
func
,
Class
<
T
>
clz
)
{
T
value
=
localCache
.
get
(
key
,
clz
);
...
...
community-service/src/main/java/com/tanpu/community/service/BatchFeignCallService.java
View file @
30e71043
...
...
@@ -197,7 +197,8 @@ public class BatchFeignCallService {
}
if
(!
CollectionUtils
.
isEmpty
(
curriculumIds
))
{
// 课程列表
List
<
ShortVideoBaseInfoResp
>
commonResp
=
feignService
.
getCurriculumByColumnRelId
(
setToList
(
curriculumIds
));
List
<
ShortVideoBaseInfoResp
>
commonResp
=
feignClientForFatools
.
getCurriculumByColumnRelId
(
setToList
(
curriculumIds
));
if
(
commonResp
!=
null
&&
!
CollectionUtils
.
isEmpty
(
commonResp
))
{
curriculumMap
.
putAll
(
commonResp
.
stream
()
.
collect
(
Collectors
.
toMap
(
ShortVideoBaseInfoResp:
:
getColumnRelId
,
item
->
item
)));
...
...
community-service/src/main/java/com/tanpu/community/service/FeignService.java
View file @
30e71043
package
com
.
tanpu
.
community
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.community.api.beans.vo.feign.fatools.UserInfoResp
;
...
...
@@ -12,6 +13,8 @@ import com.tanpu.community.feign.product.FeignForFund;
import
com.tanpu.community.feign.product.FeignForPublicFund
;
import
com.tanpu.community.feign.tanpuroom.FeignClientForTanpuroom
;
import
com.tanpu.community.feign.zhibo.FeignClientForZhibo
;
import
lombok.extern.log4j.Log4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.caffeine.CaffeineCacheManager
;
...
...
@@ -23,6 +26,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.function.Function
;
@Slf4j
@Service
public
class
FeignService
{
...
...
@@ -61,7 +65,8 @@ public class FeignService {
}
public
List
<
ShortVideoBaseInfoResp
>
batchGetShortVideoBaseInfo
(
List
<
String
>
sourceIds
)
{
return
batchExecute
(
"batchGetShortVideoBaseInfo_"
,
sourceIds
,
ShortVideoBaseInfoResp
.
class
,
ids
->
{
return
batchExecute
(
"batchGetShortVideoBaseInfo_"
,
sourceIds
,
ShortVideoBaseInfoResp
.
class
,
ShortVideoBaseInfoResp:
:
getSourceId
,
ids
->
{
CommonResp
<
List
<
ShortVideoBaseInfoResp
>>
resp
=
feignClientForTanpuroom
.
getShortVideoBaseInfo
(
ids
);
if
(
resp
.
isSuccess
())
{
return
resp
.
getData
();
...
...
@@ -71,13 +76,11 @@ public class FeignService {
});
}
public
List
<
ShortVideoBaseInfoResp
>
getCurriculumByColumnRelId
(
List
<
String
>
curriculumIds
)
{
return
batchExecute
(
"getCurriculumByColumnRelId_"
,
curriculumIds
,
ShortVideoBaseInfoResp
.
class
,
ids
->
{
return
feignClientForFatools
.
getCurriculumByColumnRelId
(
ids
);
});
}
private
<
T
>
List
<
T
>
batchExecute
(
String
keyPrefix
,
List
<
String
>
keys
,
Class
<
T
>
clz
,
Function
<
List
<
String
>,
List
<
T
>>
func
)
{
private
<
T
>
List
<
T
>
batchExecute
(
String
keyPrefix
,
List
<
String
>
keys
,
Class
<
T
>
clz
,
Function
<
T
,
String
>
getKeyFunc
,
Function
<
List
<
String
>,
List
<
T
>>
feignFunc
)
{
List
<
T
>
retList
=
new
ArrayList
<>();
List
<
String
>
feignIds
=
new
ArrayList
<>();
for
(
String
key
:
keys
)
{
...
...
@@ -91,12 +94,16 @@ public class FeignService {
}
if
(!
feignIds
.
isEmpty
())
{
List
<
T
>
remoteList
=
func
.
apply
(
feignIds
);
List
<
T
>
remoteList
=
f
eignF
unc
.
apply
(
feignIds
);
if
(
remoteList
!=
null
)
{
retList
.
addAll
(
remoteList
);
retList
.
forEach
(
r
->
{
localCache
.
putObject
(
keyPrefix
+
getKeyFunc
.
apply
(
r
),
r
);
});
}
}
}
log
.
info
(
"batchExecute {} : {} -> {}"
,
keyPrefix
,
JSON
.
toJSONString
(
keys
),
JSON
.
toJSONString
(
retList
));
return
retList
;
}
}
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