0

I wanted to use the @Cacheable annotation for Spring Boot 1.5, without any external cache provider. How do I set the TTL for the simple provider case?

According to this question and other resources online, I can use Guava's CacheBuilder to set the expiry by providing a CacheConfiguration.

However, it seems Guava Cache is deprecated by Spring. So without Guava, how does one set the TTL for a simple Spring cache?

z11i
  • 951
  • 11
  • 26

1 Answers1

0

you can try

Ehcache

add dependency in your pom.xml

<dependency>
    <groupId>org.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>3.6.2</version>
</dependency>  

implement cache

@Service
public class NumberService {

    // ...
    @Cacheable(
      value = "squareCache", 
      key = "#number", 
      condition = "#number>10")
    public BigDecimal square(Long number) {
        BigDecimal square = BigDecimal.valueOf(number)
          .multiply(BigDecimal.valueOf(number));
        log.info("square of {} is {}", number, square);
        return square;
    }
}

more details for ref.

Istiaque Hossain
  • 2,157
  • 1
  • 17
  • 28