Consistently support LoadingCache

This commits make sure that CaffeineCache handles consistently the
contract of LoadingCache.

Closes gh-25173
This commit is contained in:
Stephane Nicoll
2020-08-07 10:38:27 +02:00
parent b6ef3cfad5
commit f3cedf268b
2 changed files with 34 additions and 11 deletions

View File

@@ -83,16 +83,6 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
return this.cache;
}
@Override
@Nullable
public ValueWrapper get(Object key) {
if (this.cache instanceof LoadingCache) {
Object value = ((LoadingCache<Object, Object>) this.cache).get(key);
return toValueWrapper(value);
}
return super.get(key);
}
@SuppressWarnings("unchecked")
@Override
@Nullable
@@ -103,6 +93,9 @@ public class CaffeineCache extends AbstractValueAdaptingCache {
@Override
@Nullable
protected Object lookup(Object key) {
if (this.cache instanceof LoadingCache) {
return ((LoadingCache<Object, Object>) this.cache).get(key);
}
return this.cache.getIfPresent(key);
}