Subversion Repositories SmartDukaan

Rev

Rev 37409 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37409 Rev 37840
Line 161... Line 161...
161
     *  - todayOffers          : Today's offers per (brand, fofoId). 60 min TTL (redisShortCacheManager).
161
     *  - todayOffers          : Today's offers per (brand, fofoId). 60 min TTL (redisShortCacheManager).
162
     */
162
     */
163
    @Override
163
    @Override
164
    public void evictOfferCaches(int offerId) {
164
    public void evictOfferCaches(int offerId) {
165
        Offer offer = offerRepository.selectById(offerId);
165
        Offer offer = offerRepository.selectById(offerId);
166
        YearMonth ym = YearMonth.from(offer.getStartDate());
166
        for (YearMonth ym : monthsCovered(offer.getStartDate(), offer.getEndDate())) {
167
        evictMonthCaches(ym);
167
            evictMonthCaches(ym);
-
 
168
        }
168
        redisCacheManager.getCache("offer.definition").evict(offerId);
169
        redisCacheManager.getCache("offer.definition").evict(offerId);
169
        redisCacheManager.getCache("offer.slabpayout").evict(offerId);
170
        redisCacheManager.getCache("offer.slabpayout").evict(offerId);
170
        redisCacheManager.getCache("offer.achievement").clear();
171
        redisCacheManager.getCache("offer.achievement").clear();
171
    }
172
    }
172
 
173
 
-
 
174
    // Month caches hold every offer overlapping the month, so an offer lives in each month from start to end
-
 
175
    private static List<YearMonth> monthsCovered(LocalDateTime startDate, LocalDateTime endDate) {
-
 
176
        List<YearMonth> months = new ArrayList<>();
-
 
177
        YearMonth last = YearMonth.from(endDate);
-
 
178
        for (YearMonth ym = YearMonth.from(startDate); !ym.isAfter(last); ym = ym.plusMonths(1)) {
-
 
179
            months.add(ym);
-
 
180
        }
-
 
181
        return months;
-
 
182
    }
-
 
183
 
173
    @Override
184
    @Override
174
    public void evictOfferDefinitionCache(int offerId) {
185
    public void evictOfferDefinitionCache(int offerId) {
175
        redisCacheManager.getCache("offer.definition").evict(offerId);
186
        redisCacheManager.getCache("offer.definition").evict(offerId);
176
    }
187
    }
177
 
188
 
Line 560... Line 571...
560
                    payoutSlab.setOnwardsAmount(targets.get(counter));
571
                    payoutSlab.setOnwardsAmount(targets.get(counter));
561
                    counter++;
572
                    counter++;
562
                }
573
                }
563
                this.addOfferService(createOfferRequest);
574
                this.addOfferService(createOfferRequest);
564
            }
575
            }
565
            ymListToEvict.add(YearMonth.from(createOfferRequest.getStartDate()));
576
            ymListToEvict.addAll(monthsCovered(createOfferRequest.getStartDate(), createOfferRequest.getEndDate()));
566
        }
577
        }
567
        for (YearMonth ymToEvict : ymListToEvict) {
578
        for (YearMonth ymToEvict : ymListToEvict) {
568
            evictMonthCaches(ymToEvict);
579
            evictMonthCaches(ymToEvict);
569
        }
580
        }
570
    }
581
    }