Without TTL feature, it's hard to use @Cacheable in real project.

For ex: I use redis for cache, and have 3 method: A method need ttl 1 days B method need ttl 2 days C method need ttl 3 days

How can I do that? It's easy with native redis command.

I know the abstraction reason, The design want have a universal cache support by any data store. https://docs.spring.io/spring-framework/reference/integration/cache/specific-config.html But it just make it less useful.

And this is common feature, you can see in stackoverflow, people use some ugly way to archive this requirement : https://stackoverflow.com/a/44203099/1686407

@CacheEvict(allEntries = true, cacheNames = { "cache_1", "cache_2" })
@Scheduled(fixedDelay = 30000)
public void cacheEvict() {
}

Some even drop spring cache, and implement by himself with native data store and AOP.

I think better way is : add this feature, and throw NotSupportedException when the data store don't have TTL support.

Thanks.

Comment From: bclozel

Duplicates #32633 and https://github.com/spring-projects/spring-framework/issues/23684 - see the discussions there for more details.

Comment From: abccbaandy

Thanks for reply, But those links doesn't answer my question.

@bclozel Let's make it simple: Can you tell me how to do my example with your design? If not, maybe your design need some improve?