Skip to content

Commit

Permalink
Change caching time to 6 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
campos20 committed Jul 22, 2024
1 parent fcef6e9 commit 6914b52
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// We should move to redis to cache the statistics instead
private static final Map<String, Pair<LocalDateTime, Object>> CACHE = new HashMap<>();
private static final String MAIN_LIST_CACHE = "MAIN_LIST_CACHE";
private static final int CACHING_TIME = 6;

@Override
public StatisticsResponseDTO sqlToStatistics(StatisticsRequestDTO statisticsRequestDTO) {
Expand Down Expand Up @@ -198,7 +199,8 @@ public StatisticsListDTO list(String term) {

if (StringUtils.isBlank(term)) {
var cache = CACHE.get(MAIN_LIST_CACHE);
if (cache != null && cache.getFirst().plusDays(1).isAfter(LocalDateTime.now())) {
if (cache != null && cache.getFirst().plusHours(CACHING_TIME)
.isAfter(LocalDateTime.now())) {
return (StatisticsListDTO) cache.getSecond();
}
}
Expand Down Expand Up @@ -232,7 +234,8 @@ public StatisticsListDTO list(String term) {
@Override
public StatisticsResponseDTO getStatistic(String path) {
var cache = CACHE.get(path);
if (cache != null && cache.getFirst().plusDays(1).isAfter(LocalDateTime.now())) {
if (cache != null && cache.getFirst().plusHours(CACHING_TIME)
.isAfter(LocalDateTime.now())) {
return (StatisticsResponseDTO) cache.getSecond();
}

Expand Down

0 comments on commit 6914b52

Please sign in to comment.