ehcache3 - why cache doesn't expire?

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I want to cache a few of my dao queries. And it works, but cache doesn't expire. What I'm doing wrong?

My ehcache.xml:

 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">
    java.lang.String
    xxx.model.SignalValueType
        
             unit="seconds">5
        

        
             unit="entries">100
             unit="MB">10
        
    cache> 

In application.properties I have entry:

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

In pom:

<dependency>
    javax.cache
    cache-api
    runtime
dependency>
<dependency>
    org.ehcache
    ehcache
dependency>

And my query:

@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;
}

I expect 5 seconds expiring, but after this time (and longer) query is still cached. What I'm doing wrong?

profilepic.png
manpreet 2 years ago

Shouldn't be ehcache instead of jcache?

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

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.