|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.cache.concurrent;
|
18 | 18 |
|
19 |
| -import org.springframework.cache.Cache; |
20 |
| -import org.springframework.cache.support.SimpleValueWrapper; |
21 |
| - |
22 | 19 | import java.io.Serializable;
|
23 | 20 | import java.util.concurrent.ConcurrentHashMap;
|
24 | 21 | import java.util.concurrent.ConcurrentMap;
|
25 | 22 |
|
| 23 | +import org.springframework.cache.Cache; |
| 24 | +import org.springframework.cache.support.SimpleValueWrapper; |
| 25 | +import org.springframework.util.Assert; |
| 26 | + |
26 | 27 | /**
|
27 |
| - * Simple {@link Cache} implementation based on the core JDK |
28 |
| - * {@code java.util.concurrent} package. |
| 28 | + * Simple {@link org.springframework.cache.Cache} implementation based on the |
| 29 | + * core JDK {@code java.util.concurrent} package. |
29 | 30 | *
|
30 | 31 | * <p>Useful for testing or simple caching scenarios, typically in combination
|
31 | 32 | * with {@link org.springframework.cache.support.SimpleCacheManager} or
|
@@ -62,21 +63,24 @@ public ConcurrentMapCache(String name) {
|
62 | 63 | /**
|
63 | 64 | * Create a new ConcurrentMapCache with the specified name.
|
64 | 65 | * @param name the name of the cache
|
65 |
| - * @param allowNullValues whether to accept and convert null values for this cache |
| 66 | + * @param allowNullValues whether to accept and convert {@code null} |
| 67 | + * values for this cache |
66 | 68 | */
|
67 | 69 | public ConcurrentMapCache(String name, boolean allowNullValues) {
|
68 | 70 | this(name, new ConcurrentHashMap<Object, Object>(256), allowNullValues);
|
69 | 71 | }
|
70 | 72 |
|
71 | 73 | /**
|
72 | 74 | * Create a new ConcurrentMapCache with the specified name and the
|
73 |
| - * given internal ConcurrentMap to use. |
| 75 | + * given internal {@link ConcurrentMap} to use. |
74 | 76 | * @param name the name of the cache
|
75 | 77 | * @param store the ConcurrentMap to use as an internal store
|
76 | 78 | * @param allowNullValues whether to allow {@code null} values
|
77 | 79 | * (adapting them to an internal null holder value)
|
78 | 80 | */
|
79 | 81 | public ConcurrentMapCache(String name, ConcurrentMap<Object, Object> store, boolean allowNullValues) {
|
| 82 | + Assert.notNull(name, "Name must not be null"); |
| 83 | + Assert.notNull(store, "Store must not be null"); |
80 | 84 | this.name = name;
|
81 | 85 | this.store = store;
|
82 | 86 | this.allowNullValues = allowNullValues;
|
@@ -142,6 +146,10 @@ protected Object toStoreValue(Object userValue) {
|
142 | 146 |
|
143 | 147 | @SuppressWarnings("serial")
|
144 | 148 | private static class NullHolder implements Serializable {
|
| 149 | + |
| 150 | + private Object readResolve() { |
| 151 | + return NULL_HOLDER; |
| 152 | + } |
145 | 153 | }
|
146 | 154 |
|
147 | 155 | }
|
0 commit comments