licailing 3 лет назад
Родитель
Сommit
fe784d8d3d

+ 3 - 3
src/main/java/com/izouma/nineth/service/CacheService.java

@@ -75,9 +75,9 @@ public class CacheService {
     public void clearOrderPriceTrend() {
     }
 
-    @Scheduled(fixedRate = 120000)
-    @CacheEvict(value = "top", allEntries = true)
-    public void clearTop() {
+//    @Scheduled(fixedRate = 120000)
+    @CacheEvict(value = "top", key = "#month")
+    public void clearTop(int month) {
     }
 
 }

+ 8 - 1
src/main/java/com/izouma/nineth/web/StatisticController.java

@@ -5,6 +5,7 @@ import com.izouma.nineth.service.StatisticService;
 import lombok.AllArgsConstructor;
 import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -47,7 +48,7 @@ public class StatisticController {
     }
 
     @GetMapping("/top")
-    @Cacheable("top")
+    @CachePut(value = "top", key = "#month")
     public String top(int year, int month) {
         LocalDateTime start = LocalDateTime.of(year, month, 1, 0, 0, 0);
         LocalDateTime end = start.plusMonths(1).minusSeconds(1);
@@ -62,4 +63,10 @@ public class StatisticController {
         LocalDateTime start = LocalDateTime.of(endDate.minusDays(6), LocalTime.MIN);
         return statisticService.top(start, LocalDateTime.of(endDate, LocalTime.MAX), 50);
     }
+
+    @Scheduled(fixedRate = 120000)
+    private void clearTop() {
+        int monthValue = LocalDate.now().getMonthValue();
+        cacheService.clearTop(monthValue);
+    }
 }