스케줄러를 사용하여 주기적으로 캐시를 제거하는 서비스 메소드를 호출 할 수 있습니다.
스케줄러 :
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.beans.factory.annotation.Autowired;
public class Scheduler {
@Autowired
private SomeService someService;
@Scheduled(fixedRate = 10000)
public void evictCaches() {
someService.evictCaches();
}
}
서비스 :
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class SomeService {
@CacheEvict(value = { "cache1", "cache2" }, allEntries = true)
public void evictAllCaches() {
}
}