首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ehcache3 -为什么缓存不过期?

ehcache3 -为什么缓存不过期?
EN

Stack Overflow用户
提问于 2019-04-05 12:51:27
回答 1查看 311关注 0票数 1

我想缓存一些我的dao查询。它可以工作,但缓存不会过期。我哪里做错了?

我的ehcache.xml:

代码语言:javascript
复制
<config xmlns='http://www.ehcache.org/v3'
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
        xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.0.xsd
                            http://www.ehcache.org/v3/jsr107 http://www.ehcache.org/schema/ehcache-107-ext-3.0.xsd">

    <cache alias="test">
    <key-type>java.lang.String</key-type>
    <value-type>xxx.model.SignalValueType</value-type>
        <expiry>
            <ttl unit="seconds">5</ttl>
        </expiry>

        <resources>
            <heap unit="entries">100</heap>
            <offheap unit="MB">10</offheap>
        </resources>
    </cache> 
</config>

在application.properties中,我有以下条目:

代码语言:javascript
复制
spring.cache.jcache.config=classpath:ehcache.xml

在pom中:

代码语言:javascript
复制
<dependency>
    <groupId>javax.cache</groupId>
    <artifactId>cache-api</artifactId>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.ehcache</groupId>
    <artifactId>ehcache</artifactId>
</dependency>

我的问题是:

代码语言:javascript
复制
@Cacheable(value = "test", key = "#code")
@Override
public SignalValueType getSignalValueType(String code) {         
  SignalValueType signalType = (SignalValueType) sf.getCurrentSession()
.createQuery("FROM SignalValueType svt WHERE svt.code = :code").setParameter("code", code)
.uniqueResult();

 return signalType;
}

我预计会有5秒过期,但在此之后(以及更长的时间)查询仍会被缓存。我哪里做错了?

EN

回答 1

Stack Overflow用户

发布于 2019-04-05 13:01:31

不应该是ehcache而不是jcache

代码语言:javascript
复制
spring.cache.ehcache.config= {ehcache config location}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55528443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档