即使在春季启动中设置了ttl时间后,Eh Cache 3.6.0 @Cacheable也不会过期

时间:2018-12-10 12:03:12

标签: spring spring-boot ehcache ehcache-3

我在春季启动应用程序中使用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;
    }

Application.java

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

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

0 个答案:

没有答案