title: Redis: Set different time to live for methods annotated with @Cacheable
body: <p>I have a set of cached methods that look somewhat like this:</p>
  
  <pre><code>@Cacheable(value = "myCacheName", keyGenerator = "myKeyGenerator")
  public Product getProduct(ProductRequest request) {
      // ...
  }
  </code></pre>
  
  <p>And I need to set different time to live (expiration interval) for objects returned by these methods.</p>
  
  <p><strong>Problem:</strong> According to <a href="https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis.repositories.expirations" rel="noreferrer">the documentation</a>, the offered way is using <code>@RedisHash(timeToLive=…​)</code> or <code>@TimeToLive</code> annotations on the return type of the methods. However, I don't want to pollute my domain classes with caching related logic. In addition, some of my methods return strings or objects of classes which I can not modify. I would prefer to implement it in a more configurable way. There is also a configuration property called <code>spring.cache.redis.time-to-live</code>, but it applies the same time-to-live in all places.</p>
  
  <p><strong>Question:</strong> Is there a way to specify time to live/expiration interval on the method level? Or generally, how to implement it in a more elegant way?</p>