SPR-8023
+ fix bug in Ehcache cache that considered expired entries for key checks
This commit is contained in:
Costin Leau
2011-03-06 11:36:36 +00:00
parent d7a8cf4b7e
commit 523a83ca28
3 changed files with 32 additions and 13 deletions

View File

@@ -58,10 +58,14 @@ public class EhCacheCache implements Cache<Object, Object> {
}
public boolean containsKey(Object key) {
return cache.isKeyInCache(key);
// get the element to force the expiry check (since #isKeyInCache does not considers that)
Element element = cache.getQuiet(key);
return (element != null ? true : false);
}
public boolean containsValue(Object value) {
// force expiry check to guarantee a valid result (otherwise expired elements are considered)
cache.evictExpiredElements();
return cache.isValueInCache(value);
}
@@ -77,11 +81,8 @@ public class EhCacheCache implements Cache<Object, Object> {
}
public Object remove(Object key) {
Object value = null;
if (cache.isKeyInCache(key)) {
Element element = cache.getQuiet(key);
value = (element != null ? element.getObjectValue() : null);
}
Element element = cache.getQuiet(key);
Object value = (element != null ? element.getObjectValue() : null);
cache.remove(key);
return value;
}