Merge pull request 'fix: cache refresh v2' (#123) from dev into master
Reviewed-on: #123
This commit is contained in:
commit
72f8a27272
@ -58,6 +58,7 @@ public class ResultService {
|
||||
@Inject
|
||||
@CacheName("club-classement")
|
||||
Cache cacheClubClassement;
|
||||
private static final HashMap<String, Long> cacheClubClassementExp = new HashMap<>();
|
||||
|
||||
private static final HashMap<Long, String> combTempIds = new HashMap<>();
|
||||
|
||||
@ -754,11 +755,10 @@ public class ResultService {
|
||||
public Uni<List<ClubClassement>> getAllClubArray(String uuid, boolean cache) {
|
||||
List<CardModel> cards = new java.util.ArrayList<>();
|
||||
|
||||
//noinspection unchecked
|
||||
return cacheClubClassement.invalidateIf(
|
||||
(p) -> ((Pair<Long, List<ClubClassement>>) p).getKey() > System.currentTimeMillis())
|
||||
.chain(__ -> cache ? Uni.createFrom().voidItem() : cacheClubClassement.invalidate(uuid))
|
||||
.chain(o -> cacheClubClassement.getAsync(uuid, k -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
return (!cache || cacheClubClassementExp.getOrDefault(uuid, 0L) < System.currentTimeMillis() ?
|
||||
cacheClubClassement.invalidate(uuid).invoke(() -> cacheClubClassementExp.remove(uuid)) :
|
||||
Uni.createFrom().voidItem()
|
||||
).chain(o -> cacheClubClassement.getAsync(uuid, k -> cardRepository.list("competition.uuid = ?1", uuid)
|
||||
.invoke(__ -> System.out.println("Cache miss for club classement with uuid " + uuid))
|
||||
.invoke(cards::addAll)
|
||||
.chain(__ -> matchRepository.list("category.compet.uuid = ?1", uuid))
|
||||
@ -834,8 +834,8 @@ public class ResultService {
|
||||
.thenComparingInt(c -> c.score[2]).reversed())
|
||||
.toList();
|
||||
})
|
||||
.map(l -> new Pair<>(System.currentTimeMillis() + 60 * 1000L, l))
|
||||
).map(Pair::getValue));
|
||||
.invoke(__ -> cacheClubClassementExp.put(uuid, System.currentTimeMillis() + 60 * 1000L))
|
||||
));
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user