|
15 | 15 | */
|
16 | 16 | package org.springframework.data.redis.cache;
|
17 | 17 |
|
18 |
| -import java.lang.reflect.Field; |
19 | 18 | import java.nio.ByteBuffer;
|
20 | 19 | import java.nio.charset.Charset;
|
21 | 20 | import java.util.concurrent.Callable;
|
|
29 | 28 | import org.springframework.lang.Nullable;
|
30 | 29 | import org.springframework.util.Assert;
|
31 | 30 | import org.springframework.util.ObjectUtils;
|
32 |
| -import org.springframework.util.ReflectionUtils; |
33 | 31 |
|
34 | 32 | /**
|
35 | 33 | * {@link org.springframework.cache.Cache} implementation using for Redis as underlying store.
|
|
39 | 37 | */
|
40 | 38 | public class RedisCache extends AbstractValueAdaptingCache {
|
41 | 39 |
|
42 |
| - private static final NullValue NULL_VALUE; |
43 |
| - private static final byte[] BINARY_NULL_VALUE; |
| 40 | + private static final byte[] BINARY_NULL_VALUE = new JdkSerializationRedisSerializer().serialize(NullValue.INSTANCE); |
44 | 41 |
|
45 | 42 | private final String name;
|
46 | 43 | private final RedisCacheWriter cacheWriter;
|
47 | 44 | private final RedisCacheConfiguration cacheConfig;
|
48 | 45 | private final ConfigurableConversionService conversionService = new DefaultFormattingConversionService();
|
49 | 46 |
|
50 |
| - static { |
51 |
| - |
52 |
| - Field field = ReflectionUtils.findField(NullValue.class, "INSTANCE"); |
53 |
| - ReflectionUtils.makeAccessible(field); |
54 |
| - NULL_VALUE = NullValue.class.cast(ReflectionUtils.getField(field, null)); |
55 |
| - |
56 |
| - BINARY_NULL_VALUE = new JdkSerializationRedisSerializer().serialize(NULL_VALUE); |
57 |
| - } |
58 |
| - |
59 | 47 | /**
|
60 | 48 | * Create new {@link RedisCache}.
|
61 | 49 | *
|
@@ -183,7 +171,7 @@ protected Object preProcessCacheValue(@Nullable Object value) {
|
183 | 171 | return value;
|
184 | 172 | }
|
185 | 173 |
|
186 |
| - return isAllowNullValues() ? NULL_VALUE : null; |
| 174 | + return isAllowNullValues() ? NullValue.INSTANCE : null; |
187 | 175 | }
|
188 | 176 |
|
189 | 177 | /**
|
@@ -221,7 +209,7 @@ protected byte[] serializeCacheValue(Object value) {
|
221 | 209 | protected Object deserializeCacheValue(byte[] value) {
|
222 | 210 |
|
223 | 211 | if (isAllowNullValues() && ObjectUtils.nullSafeEquals(value, BINARY_NULL_VALUE)) {
|
224 |
| - return NULL_VALUE; |
| 212 | + return NullValue.INSTANCE; |
225 | 213 | }
|
226 | 214 |
|
227 | 215 | return cacheConfig.getValueSerializationPair().read(ByteBuffer.wrap(value));
|
|
0 commit comments