title: How to set expiration for @Cacheable in Spring Boot?
body: <p>I have the following cache implementation in a Spring Boot app and it is working without any problem. However, I want to define expiration for this approach. Is it possible to set expiration for <code>@Cacheable</code>?</p>
  <p>I look at <strong><a href="https://stackoverflow.com/questions/27968157/expiry-time-cacheable-spring-boot">Expiry time <code>@Cacheable</code> spring boot</a></strong> and there is not seem to be a direct way for <code>@Cacheable</code>. Is it possible via a smart approach?</p>
  <pre><code>@Configuration
  @EnableCaching
  public class CachingConfig {
  
      @Bean
      public CacheManager cacheManager() {
          return new ConcurrentMapCacheManager();
      }
  }
  </code></pre>
  <pre><code>@Component
  public class SimpleCacheCustomizer 
    implements CacheManagerCustomizer&lt;ConcurrentMapCacheManager&gt; {
  
      @Override
      public void customize(ConcurrentMapCacheManager cacheManager) {
          cacheManager.setCacheNames(asList(&quot;users&quot;));
      }
  }
  </code></pre>
  <pre><code>@Cacheable(&quot;users&quot;)
  public List&lt;User&gt; getUsers(UUID id) {...}
  </code></pre>