Reliable null value handling in ConcurrentMapCache, GuavaCache, JCacheCache
Issue: SPR-13553
(cherry picked from commit de93290)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -126,6 +126,10 @@ public class JCacheCache implements Cache {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class NullHolder implements Serializable {
|
||||
|
||||
private Object readResolve() {
|
||||
return NULL_HOLDER;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -16,16 +16,17 @@
|
||||
|
||||
package org.springframework.cache.concurrent;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.support.SimpleValueWrapper;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.support.SimpleValueWrapper;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple {@link Cache} implementation based on the core JDK
|
||||
* {@code java.util.concurrent} package.
|
||||
* Simple {@link org.springframework.cache.Cache} implementation based on the
|
||||
* core JDK {@code java.util.concurrent} package.
|
||||
*
|
||||
* <p>Useful for testing or simple caching scenarios, typically in combination
|
||||
* with {@link org.springframework.cache.support.SimpleCacheManager} or
|
||||
@@ -62,7 +63,8 @@ public class ConcurrentMapCache implements Cache {
|
||||
/**
|
||||
* Create a new ConcurrentMapCache with the specified name.
|
||||
* @param name the name of the cache
|
||||
* @param allowNullValues whether to accept and convert null values for this cache
|
||||
* @param allowNullValues whether to accept and convert {@code null}
|
||||
* values for this cache
|
||||
*/
|
||||
public ConcurrentMapCache(String name, boolean allowNullValues) {
|
||||
this(name, new ConcurrentHashMap<Object, Object>(256), allowNullValues);
|
||||
@@ -70,13 +72,15 @@ public class ConcurrentMapCache implements Cache {
|
||||
|
||||
/**
|
||||
* Create a new ConcurrentMapCache with the specified name and the
|
||||
* given internal ConcurrentMap to use.
|
||||
* given internal {@link ConcurrentMap} to use.
|
||||
* @param name the name of the cache
|
||||
* @param store the ConcurrentMap to use as an internal store
|
||||
* @param allowNullValues whether to allow {@code null} values
|
||||
* (adapting them to an internal null holder value)
|
||||
*/
|
||||
public ConcurrentMapCache(String name, ConcurrentMap<Object, Object> store, boolean allowNullValues) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
Assert.notNull(store, "Store must not be null");
|
||||
this.name = name;
|
||||
this.store = store;
|
||||
this.allowNullValues = allowNullValues;
|
||||
@@ -142,6 +146,10 @@ public class ConcurrentMapCache implements Cache {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class NullHolder implements Serializable {
|
||||
|
||||
private Object readResolve() {
|
||||
return NULL_HOLDER;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user