Note that there are some explanatory texts on larger screens.

plurals
  1. POhibernate ehcache timeToLiveSeconds not working
    primarykey
    data
    text
    <p>I am using query cache in <strong>Spring Data</strong>, <strong>Hibernate</strong>, <strong>ehcache</strong> environment. The ehcache dependency is <code>compile 'org.hibernate:hibernate-ehcache:3.3.1.GA'</code></p> <p>The ehcache dependency tree is </p> <pre><code>+--- org.hibernate:hibernate-ehcache:3.3.1.GA | +--- org.hibernate:hibernate-core:3.3.1.GA -&gt; 3.6.6.Final (*) | +--- net.sf.ehcache:ehcache:1.2.3 | | \--- commons-collections:commons-collections:2.1 -&gt; 3.2.1 | \--- org.slf4j:slf4j-api:1.5.2 -&gt; 1.6.5 </code></pre> <p>I have a <code>resources/ehcache.xml</code> with <code>timeToLiveSeconds</code> configured to <strong>5 minutes</strong>.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"&gt; &lt;diskStore path="/home/prayag/cache_"/&gt; &lt;defaultCache eternal="false" maxElementsInMemory="1000" overflowToDisk="true" diskPersistent="true" timeToLiveSeconds="300" diskExpiryThreadIntervalSeconds="300" memoryStoreEvictionPolicy="LRU" /&gt; &lt;/ehcache&gt; </code></pre> <p>Caching works but after 5 minutes, <strong>cache doesn't get auto-flushed</strong> and no new changes are shown.</p> <p>Not even following code <a href="https://stackoverflow.com/a/6198959/432903">to remove cache</a> works.</p> <pre><code>import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; CacheManager cacheManager = CacheManager.getInstance(); String[] names = cacheManager.getCacheNames(); for (String name : names) { if (name.equals("merchantServices")) { Cache cache = cacheManager.getCache(name); cache.removeAll(); } } </code></pre> <h3>My Caching configuration(jpa-context.xml) with cacheName merchantServices is</h3> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns:p="http://www.springframework.org/schema/p" xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd" default-autowire="byName"&gt; &lt;tx:annotation-driven /&gt; &lt;cache:annotation-driven /&gt; &lt;bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager"&gt; &lt;property name="caches"&gt; &lt;set&gt; &lt;bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="merchantServices"/&gt; &lt;/set&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>Caching files at diskStore are as below,</p> <pre><code>prayag@prayag:~/cache_$ ls -l total 4 -rw-rw-r-- 1 prayag prayag 0 Sep 20 13:31 org.hibernate.cache.StandardQueryCache.data -rw-rw-r-- 1 prayag prayag 0 Sep 20 15:26 org.hibernate.cache.StandardQueryCache.index -rw-rw-r-- 1 prayag prayag 2268 Sep 20 15:24 org.hibernate.cache.UpdateTimestampsCache.data -rw-rw-r-- 1 prayag prayag 0 Sep 20 15:26 org.hibernate.cache.UpdateTimestampsCache.index </code></pre> <p><code>org.hibernate.cache.UpdateTimestampsCache.data</code> has following content. </p> <pre><code> prayag@prayag:~/cache_$ vi org.hibernate.cache.UpdateTimestampsCache.data ¬í^@^Esr^@^Vnet.sf.ehcache.Element.e^H&lt;90&gt;Iî-&lt;9d&gt;^B^@^LJ^@^LcreationTimeZ^@^GeternalJ^@^HhitCountJ^@^NlastAccessTimeJ^@^NlastUpdateTimeZ^@^KlifespanSetJ^@^TnextToLastAccessTimeI^@ timeToIdleI^@ timeToLiveJ^@^GversionL^@^Ckeyt^@^RLjava/lang/Object;L^@^Evalueq^@~^@^Axp^@^@^AA:°&lt;84&gt;Ä^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^AA:°&lt;84&gt;Ä^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A,^@^@^AA:°&lt;84&gt;Ät^@^GServicesr^@^Njava.lang.Long;&lt;8b&gt;ä&lt;90&gt;Ì&lt;8f&gt;#ß^B^@^AJ^@^Evaluexr^@^Pjava.lang.Number&lt;86&gt;¬&lt;95&gt;^]^K&lt;94&gt;à&lt;8b&gt;^B^@^@xp^@^T^S«^HL0^@^@°^@¬í^@^Esr^@^Vnet.sf.ehcache.Element.e^H&lt;90&gt;Iî-&lt;9d&gt;^B^@^LJ^@^LcreationTimeZ^@^GeternalJ^@^HhitCountJ^@^NlastAccessTimeJ^@^NlastUpdateTimeZ^@^KlifespanSetJ^@^TnextToLastAccessTimeI^@ timeToIdleI^@ timeToLiveJ^@^GversionL^@^Ckeyt^@^RLjava/lang/Object;L^@^Evalueq^@~^@^Axp^@^@^AA:°&lt;84&gt;Ä^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^AA:°&lt;84&gt;Ä^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A,^@^@^AA:°&lt;84&gt;Ät^@^Lservice_tagssr^@^Njava.lang.Long;&lt;8b&gt;ä&lt;90&gt;Ì&lt;8f&gt;#ß^B^@^AJ^@^Evaluexr^@^Pjava.lang.Number&lt;86&gt;¬&lt;95&gt;^]^K&lt;94&gt;à&lt;8b&gt;^B^@^@xp^@^T^S«^HL0^@^T^S¥[\°^@¬í^@^Esr^@^Vnet.sf.ehcache.Element.e^H&lt;90&gt;Iî-&lt;9d&gt;^B^@^LJ^@^LcreationTimeZ^@^GeternalJ^@^HhitCountJ^@^NlastAccessTimeJ^@^NlastUpdateTimeZ^@^KlifespanSetJ^@^TnextToLastAccessTimeI^@ timeToIdleI^@ timeToLiveJ^@^GversionL^@^Ckeyt^@^RLjava/lang/Object;L^@^Evalueq^@~^@^Axp^@^@^AA:±%^Q^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^AA:±%^Q^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A,^@^@^AA:±%^Qt^@ SessionLogsr^@^Njava.lang.Long;&lt;8b&gt;ä&lt;90&gt;Ì&lt;8f&gt;#ß^B^@^AJ^@^Evaluexr^@^Pjava.lang.Number&lt;86&gt;¬&lt;95&gt;^]^K&lt;94&gt;à&lt;8b&gt;^B^@^@xp^@^T^S«^RQ^@^@^@¬í^@^Esr^@^Vnet.sf.ehcache.Element.e^H&lt;90&gt;Iî-&lt;9d&gt;^B^@^LJ^@^LcreationTimeZ^@^GeternalJ^@^HhitCountJ^@^NlastAccessTimeJ^@^NlastUpdateTimeZ^@^KlifespanSetJ^@^TnextToLastAccessTimeI^@ timeToIdleI^@ timeToLiveJ^@^GversionL^@^Ckeyt^@^RLjava/lang/Object;L^@^Evalueq^@~^@^Axp^@^@^AA:°&lt;84&gt;Ä^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^AA:°&lt;84&gt;Ä^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A,^@^@^AA:°&lt;84&gt;Ät^@^SServiceAccessStatussr^@^Njava.lang.Long;&lt;8b&gt;ä&lt;90&gt;Ì&lt;8f&gt;#ß^B^@^AJ^@^Evaluexr^@^Pjava.lang.Number&lt;86&gt;¬&lt;95&gt;^]^K&lt;94&gt;à&lt;8b&gt;^B^@^@xp^@^T^S«^HL0^@¬í^@^Esr^@^Vnet.sf.ehcache.Element.e^H&lt;90&gt;Iî-&lt;9d&gt;^B^@^LJ^@^LcreationTimeZ^@^GeternalJ^@^HhitCountJ^@^NlastAccessTimeJ^@^NlastUpdateTimeZ^@^KlifespanSetJ^@^TnextToLastAccessTimeI^@ timeToIdleI^@ timeToLiveJ^@^GversionL^@^Ckeyt^@^RLjava/lang/Object;L^@^Evalueq^@~^@^Axp^@^@^AA:°&lt;84&gt;Ä^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^AA:°&lt;84&gt;Ä^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A,^@^@^AA:°&lt;84&gt;Ät^@^HBankInfosr^@^Njava.lang.Long;&lt;8b&gt;ä&lt;90&gt;Ì&lt;8f&gt;#ß^B^@^AJ^@^Evaluexr^@^Pjava.lang.Number&lt;86&gt;¬&lt;95&gt;^]^K&lt;94&gt;à&lt;8b&gt;^B^@^@xp^@^T^S«^HL0^@¬í^@^Esr^@^Vnet.sf.ehcache.Element.e^H&lt;90&gt;Iî-&lt;9d&gt;^B^@^LJ^@^LcreationTimeZ^@^GeternalJ^@^HhitCountJ^@^NlastAccessTimeJ^@^NlastUpdateTimeZ^@^KlifespanSetJ^@^TnextToLastAccessTimeI^@ timeToIdleI^@ timeToLiveJ^@^GversionL^@^Ckeyt^@^RLjava/lang/Object;L^@^Evalueq^@~^@^Axp^@^@^AA:¼ó1^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^AA:¼ó1^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A,^@^@^AA:¼ó1t^@^KUserSessionsr^@^Njava.lang.Long;&lt;8b&gt;ä&lt;90&gt;Ì&lt;8f&gt;#ß^B^@^AJ^@^Evaluexr^@^Pjava.lang.Number&lt;86&gt;¬&lt;95&gt;^]^K&lt;94&gt;à&lt;8b&gt;^B^@^@xp^@^T^S«Ï3^@^@ </code></pre> <p>More of my configuration is here in earlier post <a href="https://stackoverflow.com/q/18872643/432903">Spring Data + Hibernate Query Caching not working</a></p> <h3>References</h3> <p><a href="https://forum.hibernate.org/viewtopic.php?f=1&amp;t=958254" rel="nofollow noreferrer">refresh/reset EHCache regions</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload