首页 > 解决方案 > Eh Cache 3.6.0 @Cacheable 即使在 Spring Boot 中设置了 ttl 时间后也不会过期

问题描述

我在我的 Spring Boot 应用程序中使用 EhCache 3.6.0 进行缓存。

POM.xml

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

        <!-- Spring Framework Caching Support -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>   

ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="ehcache.xsd"
         updateCheck="true"
         monitoring="autodetect"
         dynamicConfig="true">         

    <cache name="customattributes"
           maxElementsInMemory="100"
           eternal="false"
           overflowToDisk="false"
           timeToLiveSeconds="60"
           timeToIdleSeconds="0"
           memoryStoreEvictionPolicy="LFU"                    
           transactionalMode="off">           
    </cache>    
</ehcache>

ServiceImpl.java

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
    @Override
    @Cacheable("customattributes")
    public List<custom> getcustom(Long id)
    {
         List<Custom> customList =dao.getAllCustoms();
        return customList;
    }

应用程序.java

@SpringBootApplication
@EnableCaching
public class LeadApplication
{  
    public static void main(String[] args)
    {
        SpringApplication.run(LeadApplication.class, args);
    }
}

请指导我在 Spring Boot 应用程序中设置 ttl 时间后过期缓存。

标签: springspring-bootehcacheehcache-3

解决方案


推荐阅读