【问题标题】:ehcache3 - why cache doesn't expire?ehcache3 - 为什么缓存不会过期?
【发布时间】:2019-08-26 22:44:27
【问题描述】:

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

我的 ehcache.xml:

<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 我有条目:

spring.cache.jcache.config=classpath:ehcache.xml

在 pom 中:

<dependency>
    <groupId>javax.cache</groupId>
    <artifactId>cache-api</artifactId>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.ehcache</groupId>
    <artifactId>ehcache</artifactId>
</dependency>

我的查询:

@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 秒到期,但在此时间(和更长)之后,查询仍会被缓存。我做错了什么?

【问题讨论】:

    标签: java hibernate maven spring-boot ehcache-3


    【解决方案1】:

    不应该是ehcache 而不是jcache

    spring.cache.ehcache.config= {ehcache config location}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-09
      • 1970-01-01
      • 2013-01-14
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      • 1970-01-01
      • 2023-04-07
      相关资源
      最近更新 更多