|
|
|
@ -16,9 +16,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.cache.concurrent; |
|
|
|
package org.springframework.cache.concurrent; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.util.concurrent.Callable; |
|
|
|
import java.util.concurrent.Callable; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
import java.util.concurrent.ConcurrentMap; |
|
|
|
import java.util.concurrent.ConcurrentMap; |
|
|
|
@ -45,6 +42,7 @@ import org.springframework.util.Assert; |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Stephane Nicoll |
|
|
|
* @author Stephane Nicoll |
|
|
|
* @since 3.1 |
|
|
|
* @since 3.1 |
|
|
|
|
|
|
|
* @see ConcurrentMapCacheManager |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ConcurrentMapCache extends AbstractValueAdaptingCache { |
|
|
|
public class ConcurrentMapCache extends AbstractValueAdaptingCache { |
|
|
|
|
|
|
|
|
|
|
|
@ -190,7 +188,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache { |
|
|
|
Object storeValue = super.toStoreValue(userValue); |
|
|
|
Object storeValue = super.toStoreValue(userValue); |
|
|
|
if (this.serialization != null) { |
|
|
|
if (this.serialization != null) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return serializeValue(this.serialization, storeValue); |
|
|
|
return this.serialization.serializeToByteArray(storeValue); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
throw new IllegalArgumentException("Failed to serialize cache value '" + userValue + |
|
|
|
throw new IllegalArgumentException("Failed to serialize cache value '" + userValue + |
|
|
|
@ -202,17 +200,11 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Object serializeValue(SerializationDelegate serialization, Object storeValue) throws IOException { |
|
|
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
serialization.serialize(storeValue, out); |
|
|
|
|
|
|
|
return out.toByteArray(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected Object fromStoreValue(@Nullable Object storeValue) { |
|
|
|
protected Object fromStoreValue(@Nullable Object storeValue) { |
|
|
|
if (storeValue != null && this.serialization != null) { |
|
|
|
if (storeValue != null && this.serialization != null) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return super.fromStoreValue(deserializeValue(this.serialization, storeValue)); |
|
|
|
return super.fromStoreValue(this.serialization.deserializeFromByteArray((byte[]) storeValue)); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
throw new IllegalArgumentException("Failed to deserialize cache value '" + storeValue + "'", ex); |
|
|
|
throw new IllegalArgumentException("Failed to deserialize cache value '" + storeValue + "'", ex); |
|
|
|
@ -221,12 +213,6 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache { |
|
|
|
else { |
|
|
|
else { |
|
|
|
return super.fromStoreValue(storeValue); |
|
|
|
return super.fromStoreValue(storeValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static Object deserializeValue(SerializationDelegate serialization, Object storeValue) throws IOException { |
|
|
|
|
|
|
|
ByteArrayInputStream in = new ByteArrayInputStream((byte[]) storeValue); |
|
|
|
|
|
|
|
return serialization.deserialize(in); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|