Restore proper use of CacheLoader
Since Guava 11, CacheLoader is only invoked with a LoadingCache but the GuavaCache wrapper is always invoking getIfPresent(), available on the main Guava Cache interface. Update GuavaCache#get to check for the presence of a LoadingCache and call the appropriate method. Issue: SPR-12842
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,9 @@ import java.io.Serializable;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.support.SimpleValueWrapper;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -88,8 +91,16 @@ public class GuavaCache implements Cache {
|
||||
|
||||
@Override
|
||||
public ValueWrapper get(Object key) {
|
||||
Object value = this.cache.getIfPresent(key);
|
||||
return toWrapper(value);
|
||||
if (this.cache instanceof LoadingCache) {
|
||||
try {
|
||||
Object value = ((LoadingCache<Object, Object>) this.cache).get(key);
|
||||
return toWrapper(value);
|
||||
}
|
||||
catch (ExecutionException ex) {
|
||||
throw new UncheckedExecutionException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
return toWrapper(this.cache.getIfPresent(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user