EhCache does not update cache

I am using EhCache v2.3.0 in conjunction with EclipseLink v2.5.2 and EJB 3.0 in Enterprise Application.

The problem is that the EhCache object is not being updated. The expected behavior is that the cache expires after 60 seconds and reloads the data. In fact, what happens is that the cache expires after 60 seconds and reloads the old data.

This happens even if the object’s cache is set to "isolated". For testing purposes, I even set the cache type to nothing, but it does not work.

Does anyone have an idea?

Here is the ehcache.xml:

<ehcache name="testCache">
<defaultCache
    timeToIdleSeconds="60"
    timeToLiveSeconds="60"/>
<cache name="myCache"
    timeToIdleSeconds="60"
    timeToLiveSeconds="60"/></ehcache>

This loads correctly at startup in the Context-Listener. So, the cache is configured with the correct values, I checked in debug mode.

After Cache received initialization (this is Singleton), it gained access to this method:

/*
This method returns the current values in the cache as an list. 
If the elements expired, it gets the new values from the database, puts them into the cache and return them as list.
*/

public List<CacheEntries> getEntries() {

EhCache cache = cacheManager.getEhCache("myCache"); 
cache.evictExpiredElements();
List<CacheEntries> list = new ArrayList<CacheEntries>();

if(cache.getSize() == 0) {
    //get CacheEJB
    list = cacheEjb.getAll();
    for(CacheEntries e : list) {
        cache.put(new Element(e.getName(), e));
    }
}
else {
    Element element = null;
    List<String> keys = cache.getKeys();
    for(String s : keys) {
        element = cache.get(s);
        list.add((CacheEntries) element.getValue());
    }
}
return list;

}

, :

@Entity @Cache(type = CacheType.NONE, isolation = CacheIsolationType.ISOLATED) @Table ...
+4
1

EhCache JPA. JPA, persistence.xml

<persistence-unit name="ACME">
   <shared-cache-mode>NONE</shared-cache-mode>
</persistence-unit>

, @Cacheable(false) .

CacheType.NONE.

, CacheType NONE @Cache , false. [EclipseLink//JPA/]

.

Query query = em.createQuery("Select e from Employee e");
query.setHint("javax.persistence.cache.storeMode", "REFRESH");
+1

All Articles