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:
public List<CacheEntries> getEntries() {
EhCache cache = cacheManager.getEhCache("myCache");
cache.evictExpiredElements();
List<CacheEntries> list = new ArrayList<CacheEntries>();
if(cache.getSize() == 0) {
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 ...