Annotation Interface EnableTTLCaching


@Target(TYPE) @Retention(RUNTIME) @Documented @EnableCaching @Import(io.microsphere.spring.cache.annotation.TTLCachingConfiguration.class) public @interface EnableTTLCaching
Enables Spring's caching functionality with TTL (Time-To-Live) support.

This annotation is an extension of Spring's EnableCaching and provides additional Time-To-Live capabilities for cached data. It allows developers to configure the duration for which cache entries should remain valid, helping manage cache expiration more effectively.

Example Usage


 @Configuration
 @EnableTTLCaching
 public class CachingConfig {
     // Cacheable beans and configurations go here
 }
 

Customizing Behavior

You can customize the proxying behavior and order of execution like in standard Spring caching:

These settings affect how caching advice is applied across your application. For example, using the AspectJ mode enables more comprehensive interception compared to the default proxy-based approach.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    org.springframework.context.annotation.AdviceMode
    Indicate how caching advice should be applied.
    int
    Indicate the ordering of the execution of the caching advisor when multiple advices are applied at a specific joinpoint.
    boolean
    Indicate whether subclass-based (CGLIB) proxies are to be created as opposed to standard Java interface-based proxies.
  • Element Details

    • proxyTargetClass

      @AliasFor(annotation=org.springframework.cache.annotation.EnableCaching.class) boolean proxyTargetClass
      Indicate whether subclass-based (CGLIB) proxies are to be created as opposed to standard Java interface-based proxies. The default is false. Applicable only if mode() is set to AdviceMode.PROXY.

      Note that setting this attribute to true will affect all Spring-managed beans requiring proxying, not just those marked with @Cacheable. For example, other beans marked with Spring's @Transactional annotation will be upgraded to subclass proxying at the same time. This approach has no negative impact in practice unless one is explicitly expecting one type of proxy vs another, e.g. in tests.

      Default:
      false
    • mode

      @AliasFor(annotation=org.springframework.cache.annotation.EnableCaching.class) org.springframework.context.annotation.AdviceMode mode
      Indicate how caching advice should be applied.

      The default is AdviceMode.PROXY. Please note that proxy mode allows for interception of calls through the proxy only. Local calls within the same class cannot get intercepted that way; a caching annotation on such a method within a local call will be ignored since Spring's interceptor does not even kick in for such a runtime scenario. For a more advanced mode of interception, consider switching this to AdviceMode.ASPECTJ.

      Default:
      PROXY
    • order

      @AliasFor(annotation=org.springframework.cache.annotation.EnableCaching.class) int order
      Indicate the ordering of the execution of the caching advisor when multiple advices are applied at a specific joinpoint.

      The default is Ordered.LOWEST_PRECEDENCE.

      Default:
      2147483647