General Tech Bugs & Fixes . 1 year ago

ehcache3 - why cache doesn't expire?

ehcache3 - why cache doesn't expire?

2 views   1   1 likes   0 shares Tuteehub forum manpreet 1 answers
tuteehub_quiz
Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

profilepic.png

Tuteehub forum answer Answers (1)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 1 year 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:


    javax.cache
    cache-api
    runtime


    org.ehcache
    ehcache

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?

2 views   0 shares
Related Tags

AskAnything Ask Anything

Ask Me Anything

ask me anything tuteehub

Hello! How can I assist you today?
Whether you have questions, need information, or just want to chat, feel free to let me know