개발/스프링

springboot @cacheable @CacheEvict

깉니 2023. 10. 17. 15:52

@Cacheable("addresses")
public String getAddress(Customer customer) {
  // ...
  return customer.getAddress();
}

@CacheEvict(value = "addresses", allEntries = true, condition = "#customer.addressChanged")
public void updateAddress(Customer customer) {
  // ...
}

allEntries > 캐시에 저장된 값을 모두삭제

 

보통 세션(서버)에 저장하는데 클라이언트와 서버 사이의 프록시에 저장을 구현. (프록시 캐시서버)

단순히 @cacheEvict를 할 경우 해당 버튼을 동작할때마다 쿼리를 수행하므로 프로그램 속도가 느려짐.