Skip to content

Commit a71f042

Browse files
committedOct 18, 2023
Refine Javadoc and source in caching infrastructure components.
Judiciously applies minor source code refinements, such as introducing named (local) variable object references to make it clearer the arguments that are being passed to caching method parameters, in favor of self-describing code with intent. Closes #2742
1 parent 31ebe7e commit a71f042

File tree

3 files changed

+173
-159
lines changed

3 files changed

+173
-159
lines changed
 

‎src/main/java/org/springframework/data/redis/cache/RedisCache.java

+58-48
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public class RedisCache extends AbstractValueAdaptingCache {
6262

6363
static final byte[] BINARY_NULL_VALUE = RedisSerializer.java().serialize(NullValue.INSTANCE);
6464

65+
static final String CACHE_RETRIEVAL_UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE =
66+
"The Redis driver configured with RedisCache through RedisCacheWriter does not support CompletableFuture-based retrieval";
67+
6568
private final Lock lock = new ReentrantLock();
6669

6770
private final RedisCacheConfiguration cacheConfiguration;
@@ -71,16 +74,16 @@ public class RedisCache extends AbstractValueAdaptingCache {
7174
private final String name;
7275

7376
/**
74-
* Create a new {@link RedisCache} with the given {@link String name} and {@link RedisCacheConfiguration}, using the
75-
* {@link RedisCacheWriter} to execute Redis commands supporting the cache operations.
77+
* Create a new {@link RedisCache} with the given {@link String name} and {@link RedisCacheConfiguration},
78+
* using the {@link RedisCacheWriter} to execute Redis commands supporting the cache operations.
7679
*
7780
* @param name {@link String name} for this {@link Cache}; must not be {@literal null}.
78-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing the
79-
* necessary Redis commands; must not be {@literal null}.
80-
* @param cacheConfiguration {@link RedisCacheConfiguration} applied to this {@link RedisCache} on creation; must not
81-
* be {@literal null}.
81+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
82+
* by executing the necessary Redis commands; must not be {@literal null}.
83+
* @param cacheConfiguration {@link RedisCacheConfiguration} applied to this {@link RedisCache} on creation;
84+
* must not be {@literal null}.
8285
* @throws IllegalArgumentException if either the given {@link RedisCacheWriter} or {@link RedisCacheConfiguration}
83-
* are {@literal null} or the given {@link String} name for this {@link RedisCache} is {@literal null}.
86+
* are {@literal null} or the given {@link String} name for this {@link RedisCache} is {@literal null}.
8487
*/
8588
protected RedisCache(String name, RedisCacheWriter cacheWriter, RedisCacheConfiguration cacheConfiguration) {
8689

@@ -98,28 +101,27 @@ protected RedisCache(String name, RedisCacheWriter cacheWriter, RedisCacheConfig
98101
/**
99102
* Get the {@link RedisCacheConfiguration} used to configure this {@link RedisCache} on initialization.
100103
*
101-
* @return an immutable {@link RedisCacheConfiguration} used to configure this {@link RedisCache} on initialization;
102-
* never {@literal null}.
104+
* @return an immutable {@link RedisCacheConfiguration} used to configure this {@link RedisCache} on initialization.
103105
*/
104106
public RedisCacheConfiguration getCacheConfiguration() {
105107
return this.cacheConfiguration;
106108
}
107109

108110
/**
109-
* Gets the configured {@link RedisCacheWriter} used to modify Redis for cache operations.
111+
* Gets the configured {@link RedisCacheWriter} used to adapt Redis for cache operations.
110112
*
111-
* @return the configured {@link RedisCacheWriter} used to modify Redis for cache operations.
113+
* @return the configured {@link RedisCacheWriter} used to adapt Redis for cache operations.
112114
*/
113115
protected RedisCacheWriter getCacheWriter() {
114116
return this.cacheWriter;
115117
}
116118

117119
/**
118-
* Gets the configured {@link ConversionService} used to convert {@link Object cache keys} to a {@link String} when
119-
* accessing entries in the cache.
120+
* Gets the configured {@link ConversionService} used to convert {@link Object cache keys} to a {@link String}
121+
* when accessing entries in the cache.
120122
*
121-
* @return the configured {@link ConversionService} used to convert {@link Object cache keys} to a {@link String} when
122-
* accessing entries in the cache.
123+
* @return the configured {@link ConversionService} used to convert {@link Object cache keys} to a {@link String}
124+
* when accessing entries in the cache.
123125
* @see RedisCacheConfiguration#getConversionService()
124126
* @see #getCacheConfiguration()
125127
*/
@@ -142,7 +144,7 @@ public RedisCacheWriter getNativeCache() {
142144
* <p>
143145
* Statistics are accumulated per cache instance and not from the backing Redis data store.
144146
*
145-
* @return statistics object for this {@link RedisCache}.
147+
* @return {@link CacheStatistics} object for this {@link RedisCache}.
146148
* @since 2.4
147149
*/
148150
public CacheStatistics getStatistics() {
@@ -173,8 +175,8 @@ private <T> T getSynchronized(Object key, Callable<T> valueLoader) {
173175
}
174176

175177
/**
176-
* Loads the {@link Object} using the given {@link Callable valueLoader} and {@link #put(Object, Object) puts} the
177-
* {@link Object loaded value} in the cache.
178+
* Loads the {@link Object} using the given {@link Callable valueLoader} and {@link #put(Object, Object) puts}
179+
* the {@link Object loaded value} in the cache.
178180
*
179181
* @param <T> {@link Class type} of the loaded {@link Object cache value}.
180182
* @param key {@link Object key} mapped to the loaded {@link Object cache value}.
@@ -199,11 +201,13 @@ protected <T> T loadCacheValue(Object key, Callable<T> valueLoader) {
199201
@Override
200202
protected Object lookup(Object key) {
201203

202-
byte[] value = getCacheConfiguration().isTimeToIdleEnabled()
203-
? getCacheWriter().get(getName(), createAndConvertCacheKey(key), getTimeToLive(key))
204-
: getCacheWriter().get(getName(), createAndConvertCacheKey(key));
204+
byte[] binaryKey = createAndConvertCacheKey(key);
205+
206+
byte[] binaryValue = getCacheConfiguration().isTimeToIdleEnabled()
207+
? getCacheWriter().get(getName(), binaryKey, getTimeToLive(key))
208+
: getCacheWriter().get(getName(), binaryKey);
205209

206-
return value != null ? deserializeCacheValue(value) : null;
210+
return binaryValue != null ? deserializeCacheValue(binaryValue) : null;
207211
}
208212

209213
private Duration getTimeToLive(Object key) {
@@ -219,8 +223,12 @@ public void put(Object key, @Nullable Object value) {
219223

220224
Object cacheValue = processAndCheckValue(value);
221225

222-
getCacheWriter().put(getName(), createAndConvertCacheKey(key), serializeCacheValue(cacheValue),
223-
getTimeToLive(key, value));
226+
byte[] binaryKey = createAndConvertCacheKey(key);
227+
byte[] binaryValue = serializeCacheValue(cacheValue);
228+
229+
Duration timeToLive = getTimeToLive(key, value);
230+
231+
getCacheWriter().put(getName(), binaryKey, binaryValue, timeToLive);
224232
}
225233

226234
@Override
@@ -232,8 +240,11 @@ public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
232240
return get(key);
233241
}
234242

235-
byte[] result = getCacheWriter().putIfAbsent(getName(), createAndConvertCacheKey(key),
236-
serializeCacheValue(cacheValue), getTimeToLive(key, value));
243+
Duration timeToLive = getTimeToLive(key, value);
244+
245+
byte[] binaryKey = createAndConvertCacheKey(key);
246+
byte[] binaryValue = serializeCacheValue(cacheValue);
247+
byte[] result = getCacheWriter().putIfAbsent(getName(), binaryKey, binaryValue, timeToLive);
237248

238249
return result != null ? new SimpleValueWrapper(fromStoreValue(deserializeCacheValue(result))) : null;
239250
}
@@ -273,8 +284,7 @@ public void evict(Object key) {
273284
public CompletableFuture<?> retrieve(Object key) {
274285

275286
if (!getCacheWriter().supportsAsyncRetrieve()) {
276-
throw new UnsupportedOperationException(
277-
"The Redis driver configured with RedisCache through RedisCacheWriter does not support CompletableFuture-based retrieval");
287+
throw new UnsupportedOperationException(CACHE_RETRIEVAL_UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE);
278288
}
279289

280290
return retrieveValue(key).thenApply(this::nullSafeDeserializedStoreValue);
@@ -285,27 +295,28 @@ public CompletableFuture<?> retrieve(Object key) {
285295
public <T> CompletableFuture<T> retrieve(Object key, Supplier<CompletableFuture<T>> valueLoader) {
286296

287297
if (!getCacheWriter().supportsAsyncRetrieve()) {
288-
throw new UnsupportedOperationException(
289-
"The Redis driver configured with RedisCache through RedisCacheWriter does not support CompletableFuture-based retrieval");
298+
throw new UnsupportedOperationException(CACHE_RETRIEVAL_UNSUPPORTED_OPERATION_EXCEPTION_MESSAGE);
290299
}
291300

292-
return retrieveValue(key) //
293-
.thenCompose(bytes -> {
301+
return retrieveValue(key).thenCompose(bytes -> {
302+
303+
if (bytes != null) {
304+
return CompletableFuture.completedFuture((T) nullSafeDeserializedStoreValue(bytes));
305+
}
306+
307+
return valueLoader.get().thenCompose(value -> {
294308

295-
if (bytes != null) {
296-
return CompletableFuture.completedFuture((T) nullSafeDeserializedStoreValue(bytes));
297-
}
309+
Object cacheValue = processAndCheckValue(value);
298310

299-
return valueLoader.get().thenCompose(value -> {
311+
byte[] binaryKey = createAndConvertCacheKey(key);
312+
byte[] binaryValue = serializeCacheValue(cacheValue);
300313

301-
Object cacheValue = processAndCheckValue(value);
314+
Duration timeToLive = getTimeToLive(key, cacheValue);
302315

303-
return getCacheWriter()
304-
.store(getName(), createAndConvertCacheKey(key), serializeCacheValue(cacheValue),
305-
getTimeToLive(key, cacheValue)) //
306-
.thenApply(v -> value);
307-
});
308-
});
316+
return getCacheWriter().store(getName(), binaryKey, binaryValue, timeToLive)
317+
.thenApply(v -> value);
318+
});
319+
});
309320
}
310321

311322
private Object processAndCheckValue(@Nullable Object value) {
@@ -403,8 +414,8 @@ protected String createCacheKey(Object key) {
403414
*/
404415
protected String convertKey(Object key) {
405416

406-
if (key instanceof String) {
407-
return (String) key;
417+
if (key instanceof String stringKey) {
418+
return stringKey;
408419
}
409420

410421
TypeDescriptor source = TypeDescriptor.forObject(key);
@@ -429,9 +440,8 @@ protected String convertKey(Object key) {
429440
return key.toString();
430441
}
431442

432-
String message = String.format(
433-
"Cannot convert cache key %s to String; Please register a suitable Converter"
434-
+ " via 'RedisCacheConfiguration.configureKeyConverters(...)' or override '%s.toString()'",
443+
String message = String.format("Cannot convert cache key %s to String; Please register a suitable Converter"
444+
+ " via 'RedisCacheConfiguration.configureKeyConverters(...)' or override '%s.toString()'",
435445
source, key.getClass().getName());
436446

437447
throw new IllegalStateException(message);

‎src/main/java/org/springframework/data/redis/cache/RedisCacheManager.java

+93-91
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
/**
3535
* {@link CacheManager} implementation for Redis backed by {@link RedisCache}.
3636
* <p>
37-
* This {@link CacheManager} creates {@link Cache caches} on first write, by default. Empty {@link Cache caches} are not
38-
* visible in Redis due to how Redis represents empty data structures.
37+
* This {@link CacheManager} creates {@link Cache caches} on first write, by default. Empty {@link Cache caches}
38+
* are not visible in Redis due to how Redis represents empty data structures.
3939
* <p>
4040
* {@link Cache Caches} requiring a different {@link RedisCacheConfiguration cache configuration} than the
4141
* {@link RedisCacheConfiguration#defaultCacheConfig() default cache configuration} can be specified via
@@ -46,11 +46,11 @@
4646
* @author Mark Paluch
4747
* @author Yanming Zhou
4848
* @author John Blum
49-
* @see RedisCache
50-
* @see RedisCacheConfiguration
51-
* @see RedisCacheWriter
52-
* @see org.springframework.cache.CacheManager
49+
* @see org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager
5350
* @see org.springframework.data.redis.connection.RedisConnectionFactory
51+
* @see org.springframework.data.redis.cache.RedisCacheConfiguration
52+
* @see org.springframework.data.redis.cache.RedisCacheWriter
53+
* @see org.springframework.data.redis.cache.RedisCache
5454
* @since 2.0
5555
*/
5656
public class RedisCacheManager extends AbstractTransactionSupportingCacheManager {
@@ -66,17 +66,17 @@ public class RedisCacheManager extends AbstractTransactionSupportingCacheManager
6666
private final Map<String, RedisCacheConfiguration> initialCacheConfiguration;
6767

6868
/**
69-
* Creates a new {@link RedisCacheManager} initialized with the given {@link RedisCacheWriter} and a default
69+
* Creates a new {@link RedisCacheManager} initialized with the given {@link RedisCacheWriter} and default
7070
* {@link RedisCacheConfiguration}.
7171
* <p>
7272
* Allows {@link RedisCache cache} creation at runtime.
7373
*
74-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing appropriate
75-
* Redis commands; must not be {@literal null}.
76-
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches} by
77-
* default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
74+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
75+
* by executing appropriate Redis commands; must not be {@literal null}.
76+
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches}
77+
* by default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
7878
* @throws IllegalArgumentException if either the given {@link RedisCacheWriter} or {@link RedisCacheConfiguration}
79-
* are {@literal null}.
79+
* are {@literal null}.
8080
* @see org.springframework.data.redis.cache.RedisCacheConfiguration
8181
* @see org.springframework.data.redis.cache.RedisCacheWriter
8282
*/
@@ -85,17 +85,17 @@ public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration d
8585
}
8686

8787
/**
88-
* Creates a new {@link RedisCacheManager} initialized with the given {@link RedisCacheWriter} and default
89-
* {@link RedisCacheConfiguration}, and whether to allow cache creation at runtime.
88+
* Creates a new {@link RedisCacheManager} initialized with the given {@link RedisCacheWriter}
89+
* and default {@link RedisCacheConfiguration} along with whether to allow cache creation at runtime.
9090
*
91-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing appropriate
92-
* Redis commands; must not be {@literal null}.
93-
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches} by
94-
* default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
91+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
92+
* by executing appropriate Redis commands; must not be {@literal null}.
93+
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches}
94+
* by default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
9595
* @param allowRuntimeCacheCreation boolean specifying whether to allow creation of undeclared caches at runtime;
96-
* {@literal true} by default. Maybe just use {@link RedisCacheConfiguration#defaultCacheConfig()}.
96+
* {@literal true} by default. Maybe just use {@link RedisCacheConfiguration#defaultCacheConfig()}.
9797
* @throws IllegalArgumentException if either the given {@link RedisCacheWriter} or {@link RedisCacheConfiguration}
98-
* are {@literal null}.
98+
* are {@literal null}.
9999
* @see org.springframework.data.redis.cache.RedisCacheConfiguration
100100
* @see org.springframework.data.redis.cache.RedisCacheWriter
101101
* @since 2.0.4
@@ -113,19 +113,19 @@ private RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration
113113

114114
/**
115115
* Creates a new {@link RedisCacheManager} initialized with the given {@link RedisCacheWriter} and a default
116-
* {@link RedisCacheConfiguration}, along with an optional, initial set of {@link String cache names} used to create
117-
* {@link RedisCache Redis caches} on startup.
116+
* {@link RedisCacheConfiguration} along with an optional, initial set of {@link String cache names}
117+
* used to create {@link RedisCache Redis caches} on startup.
118118
* <p>
119119
* Allows {@link RedisCache cache} creation at runtime.
120120
*
121-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing appropriate
122-
* Redis commands; must not be {@literal null}.
123-
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches} by
124-
* default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
121+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
122+
* by executing appropriate Redis commands; must not be {@literal null}.
123+
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches}
124+
* by default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
125125
* @param initialCacheNames optional set of {@link String cache names} used to create {@link RedisCache Redis caches}
126-
* on startup. The default {@link RedisCacheConfiguration} will be applied to each cache.
126+
* on startup. The default {@link RedisCacheConfiguration} will be applied to each cache.
127127
* @throws IllegalArgumentException if either the given {@link RedisCacheWriter} or {@link RedisCacheConfiguration}
128-
* are {@literal null}.
128+
* are {@literal null}.
129129
* @see org.springframework.data.redis.cache.RedisCacheConfiguration
130130
* @see org.springframework.data.redis.cache.RedisCacheWriter
131131
*/
@@ -137,21 +137,21 @@ public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration d
137137

138138
/**
139139
* Creates a new {@link RedisCacheManager} initialized with the given {@link RedisCacheWriter} and default
140-
* {@link RedisCacheConfiguration}, and whether to allow cache creation at runtime.
140+
* {@link RedisCacheConfiguration} along with whether to allow cache creation at runtime.
141141
* <p>
142-
* Additionally, the optional, initial set of {@link String cache names} will be used to create {@link RedisCache
143-
* Redis caches} on startup.
142+
* Additionally, the optional, initial set of {@link String cache names} will be used to
143+
* create {@link RedisCache Redis caches} on startup.
144144
*
145-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing appropriate
146-
* Redis commands; must not be {@literal null}.
147-
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches} by
148-
* default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
145+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
146+
* by executing appropriate Redis commands; must not be {@literal null}.
147+
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches}
148+
* by default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
149149
* @param allowRuntimeCacheCreation boolean specifying whether to allow creation of undeclared caches at runtime;
150-
* {@literal true} by default. Maybe just use {@link RedisCacheConfiguration#defaultCacheConfig()}.
150+
* {@literal true} by default. Maybe just use {@link RedisCacheConfiguration#defaultCacheConfig()}.
151151
* @param initialCacheNames optional set of {@link String cache names} used to create {@link RedisCache Redis caches}
152-
* on startup. The default {@link RedisCacheConfiguration} will be applied to each cache.
152+
* on startup. The default {@link RedisCacheConfiguration} will be applied to each cache.
153153
* @throws IllegalArgumentException if either the given {@link RedisCacheWriter} or {@link RedisCacheConfiguration}
154-
* are {@literal null}.
154+
* are {@literal null}.
155155
* @see org.springframework.data.redis.cache.RedisCacheConfiguration
156156
* @see org.springframework.data.redis.cache.RedisCacheWriter
157157
* @since 2.0.4
@@ -175,15 +175,15 @@ public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration d
175175
* <p>
176176
* Allows {@link RedisCache cache} creation at runtime.
177177
*
178-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing appropriate
179-
* Redis commands; must not be {@literal null}.
180-
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches} by
181-
* default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
178+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
179+
* by executing appropriate Redis commands; must not be {@literal null}.
180+
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches}
181+
* by default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
182182
* @param initialCacheConfigurations {@link Map} of declared, known {@link String cache names} along with associated
183-
* {@link RedisCacheConfiguration} used to create and configure {@link RedisCache Reds caches} on startup;
184-
* must not be {@literal null}.
183+
* {@link RedisCacheConfiguration} used to create and configure {@link RedisCache Reds caches} on startup;
184+
* must not be {@literal null}.
185185
* @throws IllegalArgumentException if either the given {@link RedisCacheWriter} or {@link RedisCacheConfiguration}
186-
* are {@literal null}.
186+
* are {@literal null}.
187187
* @see org.springframework.data.redis.cache.RedisCacheConfiguration
188188
* @see org.springframework.data.redis.cache.RedisCacheWriter
189189
*/
@@ -200,17 +200,17 @@ public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration d
200200
* Additionally, an initial {@link RedisCache} will be created and configured using the associated
201201
* {@link RedisCacheConfiguration} for each {@link String named} {@link RedisCache} in the given {@link Map}.
202202
*
203-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing appropriate
204-
* Redis commands; must not be {@literal null}.
205-
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches} by
206-
* default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
203+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
204+
* by executing appropriate Redis commands; must not be {@literal null}.
205+
* @param defaultCacheConfiguration {@link RedisCacheConfiguration} applied to new {@link RedisCache Redis caches}
206+
* by default when no cache-specific {@link RedisCacheConfiguration} is provided; must not be {@literal null}.
207207
* @param allowRuntimeCacheCreation boolean specifying whether to allow creation of undeclared caches at runtime;
208-
* {@literal true} by default. Maybe just use {@link RedisCacheConfiguration#defaultCacheConfig()}.
208+
* {@literal true} by default. Maybe just use {@link RedisCacheConfiguration#defaultCacheConfig()}.
209209
* @param initialCacheConfigurations {@link Map} of declared, known {@link String cache names} along with the
210-
* associated {@link RedisCacheConfiguration} used to create and configure {@link RedisCache Redis caches} on
211-
* startup; must not be {@literal null}.
210+
* associated {@link RedisCacheConfiguration} used to create and configure {@link RedisCache Redis caches}
211+
* on startup; must not be {@literal null}.
212212
* @throws IllegalArgumentException if either the given {@link RedisCacheWriter} or {@link RedisCacheConfiguration}
213-
* are {@literal null}.
213+
* are {@literal null}.
214214
* @see org.springframework.data.redis.cache.RedisCacheConfiguration
215215
* @see org.springframework.data.redis.cache.RedisCacheWriter
216216
* @since 2.0.4
@@ -226,13 +226,12 @@ public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration d
226226
}
227227

228228
/**
229-
* @deprecated since 3.2. Use
230-
* {@link RedisCacheManager#RedisCacheManager(RedisCacheWriter, RedisCacheConfiguration, boolean, Map)}
231-
* instead.
229+
* @deprecated since 3.2. Use {@link RedisCacheManager#RedisCacheManager(RedisCacheWriter, RedisCacheConfiguration, boolean, Map)} instead.
232230
*/
233231
@Deprecated(since = "3.2")
234232
public RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration,
235233
Map<String, RedisCacheConfiguration> initialCacheConfigurations, boolean allowRuntimeCacheCreation) {
234+
236235
this(cacheWriter, defaultCacheConfiguration, allowRuntimeCacheCreation, initialCacheConfigurations);
237236
}
238237

@@ -250,8 +249,8 @@ public static RedisCacheManagerBuilder builder() {
250249
* Factory method returning a {@literal Builder} used to construct and configure a {@link RedisCacheManager}
251250
* initialized with the given {@link RedisCacheWriter}.
252251
*
253-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing appropriate
254-
* Redis commands; must not be {@literal null}.
252+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
253+
* by executing appropriate Redis commands; must not be {@literal null}.
255254
* @return new {@link RedisCacheManagerBuilder}.
256255
* @throws IllegalArgumentException if the given {@link RedisCacheWriter} is {@literal null}.
257256
* @see org.springframework.data.redis.cache.RedisCacheWriter
@@ -267,8 +266,8 @@ public static RedisCacheManagerBuilder builder(RedisCacheWriter cacheWriter) {
267266
* Factory method returning a {@literal Builder} used to construct and configure a {@link RedisCacheManager}
268267
* initialized with the given {@link RedisConnectionFactory}.
269268
*
270-
* @param connectionFactory {@link RedisConnectionFactory} used by the {@link RedisCacheManager} to acquire
271-
* connections to Redis when performing {@link RedisCache} operations; must not be {@literal null}.
269+
* @param connectionFactory {@link RedisConnectionFactory} used by the {@link RedisCacheManager}
270+
* to acquire connections to Redis when performing {@link RedisCache} operations; must not be {@literal null}.
272271
* @return new {@link RedisCacheManagerBuilder}.
273272
* @throws IllegalArgumentException if the given {@link RedisConnectionFactory} is {@literal null}.
274273
* @see org.springframework.data.redis.connection.RedisConnectionFactory
@@ -298,8 +297,8 @@ public static RedisCacheManagerBuilder builder(RedisConnectionFactory connection
298297
* <dd>enabled</dd>
299298
* </dl>
300299
*
301-
* @param connectionFactory {@link RedisConnectionFactory} used by the {@link RedisCacheManager} to acquire
302-
* connections to Redis when performing {@link RedisCache} operations; must not be {@literal null}.
300+
* @param connectionFactory {@link RedisConnectionFactory} used by the {@link RedisCacheManager}
301+
* to acquire connections to Redis when performing {@link RedisCache} operations; must not be {@literal null}.
303302
* @return new {@link RedisCacheManager}.
304303
* @throws IllegalArgumentException if the given {@link RedisConnectionFactory} is {@literal null}.
305304
* @see org.springframework.data.redis.connection.RedisConnectionFactory
@@ -308,9 +307,10 @@ public static RedisCacheManager create(RedisConnectionFactory connectionFactory)
308307

309308
Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
310309

311-
return new RedisCacheManager(
312-
org.springframework.data.redis.cache.RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory),
313-
RedisCacheConfiguration.defaultCacheConfig());
310+
RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
311+
RedisCacheConfiguration cacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
312+
313+
return new RedisCacheManager(cacheWriter, cacheConfiguration);
314314
}
315315

316316
/**
@@ -326,8 +326,8 @@ public boolean isAllowRuntimeCacheCreation() {
326326
* Return an {@link Collections#unmodifiableMap(Map) unmodifiable Map} containing {@link String caches name} mapped to
327327
* the {@link RedisCache} {@link RedisCacheConfiguration configuration}.
328328
*
329-
* @return unmodifiable {@link Map} containing {@link String cache name} / {@link RedisCacheConfiguration
330-
* configuration} pairs.
329+
* @return unmodifiable {@link Map} containing {@link String cache name}
330+
* / {@link RedisCacheConfiguration configuration} pairs.
331331
*/
332332
public Map<String, RedisCacheConfiguration> getCacheConfigurations() {
333333

@@ -353,8 +353,8 @@ protected RedisCacheConfiguration getDefaultCacheConfiguration() {
353353
}
354354

355355
/**
356-
* Gets a {@link Map} of {@link String cache names} to {@link RedisCacheConfiguration} objects as the initial set of
357-
* {@link RedisCache Redis caches} to create on startup.
356+
* Gets a {@link Map} of {@link String cache names} to {@link RedisCacheConfiguration} objects as the initial set
357+
* of {@link RedisCache Redis caches} to create on startup.
358358
*
359359
* @return a {@link Map} of {@link String cache names} to {@link RedisCacheConfiguration} objects.
360360
*/
@@ -363,8 +363,8 @@ protected Map<String, RedisCacheConfiguration> getInitialCacheConfiguration() {
363363
}
364364

365365
/**
366-
* Returns a reference to the configured {@link RedisCacheWriter} used to perform {@link RedisCache} operations, such
367-
* as reading from and writing to the cache.
366+
* Returns a reference to the configured {@link RedisCacheWriter} used to perform {@link RedisCache} operations,
367+
* such as reading from and writing to the cache.
368368
*
369369
* @return a reference to the configured {@link RedisCacheWriter}.
370370
* @see org.springframework.data.redis.cache.RedisCacheWriter
@@ -382,8 +382,8 @@ protected RedisCache getMissingCache(String name) {
382382
* Creates a new {@link RedisCache} with given {@link String name} and {@link RedisCacheConfiguration}.
383383
*
384384
* @param name {@link String name} for the {@link RedisCache}; must not be {@literal null}.
385-
* @param cacheConfiguration {@link RedisCacheConfiguration} used to configure the {@link RedisCache}; resolves to the
386-
* {@link #getDefaultCacheConfiguration()} if {@literal null}.
385+
* @param cacheConfiguration {@link RedisCacheConfiguration} used to configure the {@link RedisCache};
386+
* resolves to the {@link #getDefaultCacheConfiguration()} if {@literal null}.
387387
* @return a new {@link RedisCache} instance; never {@literal null}.
388388
*/
389389
protected RedisCache createRedisCache(String name, @Nullable RedisCacheConfiguration cacheConfiguration) {
@@ -416,8 +416,8 @@ public static class RedisCacheManagerBuilder {
416416
* Factory method returning a new {@literal Builder} used to create and configure a {@link RedisCacheManager} using
417417
* the given {@link RedisCacheWriter}.
418418
*
419-
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations by executing
420-
* appropriate Redis commands; must not be {@literal null}.
419+
* @param cacheWriter {@link RedisCacheWriter} used to perform {@link RedisCache} operations
420+
* by executing appropriate Redis commands; must not be {@literal null}.
421421
* @return new {@link RedisCacheManagerBuilder}.
422422
* @throws IllegalArgumentException if the given {@link RedisCacheWriter} is {@literal null}.
423423
* @see org.springframework.data.redis.cache.RedisCacheWriter
@@ -430,16 +430,17 @@ public static RedisCacheManagerBuilder fromCacheWriter(RedisCacheWriter cacheWri
430430
* Factory method returning a new {@literal Builder} used to create and configure a {@link RedisCacheManager} using
431431
* the given {@link RedisConnectionFactory}.
432432
*
433-
* @param connectionFactory {@link RedisConnectionFactory} used by the {@link RedisCacheManager} to acquire
434-
* connections to Redis when performing {@link RedisCache} operations; must not be {@literal null}.
433+
* @param connectionFactory {@link RedisConnectionFactory} used by the {@link RedisCacheManager}
434+
* to acquire connections to Redis when performing {@link RedisCache} operations; must not be {@literal null}.
435435
* @return new {@link RedisCacheManagerBuilder}.
436436
* @throws IllegalArgumentException if the given {@link RedisConnectionFactory} is {@literal null}.
437437
* @see org.springframework.data.redis.connection.RedisConnectionFactory
438438
*/
439439
public static RedisCacheManagerBuilder fromConnectionFactory(RedisConnectionFactory connectionFactory) {
440440

441-
RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(
442-
RedisAssertions.requireNonNull(connectionFactory, "ConnectionFactory must not be null"));
441+
Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
442+
443+
RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory);
443444

444445
return new RedisCacheManagerBuilder(cacheWriter);
445446
}
@@ -464,8 +465,8 @@ private RedisCacheManagerBuilder(RedisCacheWriter cacheWriter) {
464465
/**
465466
* Configure whether to allow cache creation at runtime.
466467
*
467-
* @param allowRuntimeCacheCreation boolean to allow creation of undeclared caches at runtime; {@literal true} by
468-
* default.
468+
* @param allowRuntimeCacheCreation boolean to allow creation of undeclared caches at runtime;
469+
* {@literal true} by default.
469470
* @return this {@link RedisCacheManagerBuilder}.
470471
*/
471472
public RedisCacheManagerBuilder allowCreateOnMissingCache(boolean allowRuntimeCacheCreation) {
@@ -476,9 +477,9 @@ public RedisCacheManagerBuilder allowCreateOnMissingCache(boolean allowRuntimeCa
476477
/**
477478
* Disable {@link RedisCache} creation at runtime for non-configured, undeclared caches.
478479
* <p>
479-
* {@link RedisCacheManager#getMissingCache(String)} returns {@literal null} for any non-configured, undeclared
480-
* {@link Cache} instead of a new {@link RedisCache} instance. This allows the
481-
* {@link org.springframework.cache.support.CompositeCacheManager} to participate.
480+
* {@link RedisCacheManager#getMissingCache(String)} returns {@literal null} for any non-configured,
481+
* undeclared {@link Cache} instead of a new {@link RedisCache} instance.
482+
* This allows the {@link org.springframework.cache.support.CompositeCacheManager} to participate.
482483
*
483484
* @return this {@link RedisCacheManagerBuilder}.
484485
* @see #allowCreateOnMissingCache(boolean)
@@ -518,8 +519,9 @@ public RedisCacheConfiguration cacheDefaults() {
518519
*/
519520
public RedisCacheManagerBuilder cacheDefaults(RedisCacheConfiguration defaultCacheConfiguration) {
520521

521-
this.defaultCacheConfiguration = RedisAssertions.requireNonNull(defaultCacheConfiguration,
522-
"DefaultCacheConfiguration must not be null");
522+
Assert.notNull(defaultCacheConfiguration, "DefaultCacheConfiguration must not be null");
523+
524+
this.defaultCacheConfiguration = defaultCacheConfiguration;
523525

524526
return this;
525527
}
@@ -573,8 +575,8 @@ public RedisCacheManagerBuilder transactionAware() {
573575
}
574576

575577
/**
576-
* Registers the given {@link String cache name} and {@link RedisCacheConfiguration} used to create and configure a
577-
* {@link RedisCache} on startup.
578+
* Registers the given {@link String cache name} and {@link RedisCacheConfiguration} used to create
579+
* and configure a {@link RedisCache} on startup.
578580
*
579581
* @param cacheName {@link String name} of the cache to register for creation on startup.
580582
* @param cacheConfiguration {@link RedisCacheConfiguration} used to configure the new cache on startup.
@@ -603,7 +605,7 @@ public RedisCacheManagerBuilder withInitialCacheConfigurations(
603605

604606
RedisAssertions.requireNonNull(cacheConfigurations, "CacheConfigurations must not be null")
605607
.forEach((cacheName, cacheConfiguration) -> RedisAssertions.requireNonNull(cacheConfiguration,
606-
"RedisCacheConfiguration for cache [%s] must not be null", cacheName));
608+
"RedisCacheConfiguration for cache [%s] must not be null", cacheName));
607609

608610
this.initialCaches.putAll(cacheConfigurations);
609611

@@ -624,8 +626,8 @@ public Optional<RedisCacheConfiguration> getCacheConfigurationFor(String cacheNa
624626
/**
625627
* Get the {@link Set} of cache names for which the builder holds {@link RedisCacheConfiguration configuration}.
626628
*
627-
* @return an unmodifiable {@link Set} holding the name of caches for which a {@link RedisCacheConfiguration
628-
* configuration} has been set.
629+
* @return an unmodifiable {@link Set} holding the name of caches
630+
* for which a {@link RedisCacheConfiguration configuration} has been set.
629631
* @since 2.2
630632
*/
631633
public Set<String> getConfiguredCaches() {

‎src/main/java/org/springframework/data/redis/cache/RedisCacheWriter.java

+22-20
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
import org.springframework.util.Assert;
2525

2626
/**
27-
* {@link RedisCacheWriter} provides low-level access to Redis commands ({@code SET, SETNX, GET, EXPIRE,...}) used for
28-
* caching.
27+
* {@link RedisCacheWriter} provides low-level access to Redis commands ({@code SET, SETNX, GET, EXPIRE,...})
28+
* used for caching.
2929
* <p>
3030
* The {@link RedisCacheWriter} may be shared by multiple cache implementations and is responsible for reading/writing
3131
* binary data from/to Redis. The implementation honors potential cache lock flags that might be set.
3232
* <p>
33-
* The default {@link RedisCacheWriter} implementation can be customized with {@link BatchStrategy} to tune performance
34-
* behavior.
33+
* The default {@link RedisCacheWriter} implementation can be customized with {@link BatchStrategy}
34+
* to tune performance behavior.
3535
*
3636
* @author Christoph Strobl
3737
* @author Mark Paluch
@@ -96,8 +96,9 @@ static RedisCacheWriter lockingRedisCacheWriter(RedisConnectionFactory connectio
9696
*
9797
* @param connectionFactory must not be {@literal null}.
9898
* @param sleepTime sleep time between lock access attempts, must not be {@literal null}.
99-
* @param lockTtlFunction TTL function to compute the Lock TTL. The function is called with contextual keys and values
100-
* (such as the cache name on cleanup or the actual key/value on put requests). Must not be {@literal null}.
99+
* @param lockTtlFunction TTL function to compute the Lock TTL. The function is called with contextual keys
100+
* and values (such as the cache name on cleanup or the actual key/value on put requests);
101+
* must not be {@literal null}.
101102
* @param batchStrategy must not be {@literal null}.
102103
* @return new instance of {@link DefaultRedisCacheWriter}.
103104
* @since 3.2
@@ -123,8 +124,8 @@ static RedisCacheWriter lockingRedisCacheWriter(RedisConnectionFactory connectio
123124
byte[] get(String name, byte[] key);
124125

125126
/**
126-
* Get the binary value representation from Redis stored for the given key and set the given {@link Duration TTL
127-
* expiration} for the cache entry.
127+
* Get the binary value representation from Redis stored for the given key and set
128+
* the given {@link Duration TTL expiration} for the cache entry.
128129
*
129130
* @param name must not be {@literal null}.
130131
* @param key must not be {@literal null}.
@@ -137,14 +138,14 @@ default byte[] get(String name, byte[] key, @Nullable Duration ttl) {
137138
}
138139

139140
/**
140-
* Determines whether the asynchronous {@link #retrieve(String, byte[])} and
141-
* {@link #retrieve(String, byte[], Duration)} cache operations are supported by the implementation.
141+
* Determines whether the asynchronous {@link #retrieve(String, byte[])}
142+
* and {@link #retrieve(String, byte[], Duration)} cache operations are supported by the implementation.
142143
* <p>
143-
* The main factor for whether the {@literal retrieve} operation can be supported will primarily be determined by the
144-
* Redis driver in use at runtime.
144+
* The main factor for whether the {@literal retrieve} operation can be supported will primarily be determined
145+
* by the Redis driver in use at runtime.
145146
* <p>
146-
* Returns {@literal false} by default. This will have an effect of {@link RedisCache#retrieve(Object)} and
147-
* {@link RedisCache#retrieve(Object, Supplier)} throwing an {@link UnsupportedOperationException}.
147+
* Returns {@literal false} by default. This will have an effect of {@link RedisCache#retrieve(Object)}
148+
* and {@link RedisCache#retrieve(Object, Supplier)} throwing an {@link UnsupportedOperationException}.
148149
*
149150
* @return {@literal true} if asynchronous {@literal retrieve} operations are supported by the implementation.
150151
* @since 3.2
@@ -154,7 +155,8 @@ default boolean supportsAsyncRetrieve() {
154155
}
155156

156157
/**
157-
* Returns the {@link CompletableFuture value} to which the {@link RedisCache} maps the given {@link byte[] key}.
158+
* Asynchronously retrieves the {@link CompletableFuture value} to which the {@link RedisCache}
159+
* maps the given {@link byte[] key}.
158160
* <p>
159161
* This operation is non-blocking.
160162
*
@@ -169,8 +171,8 @@ default CompletableFuture<byte[]> retrieve(String name, byte[] key) {
169171
}
170172

171173
/**
172-
* Returns the {@link CompletableFuture value} to which the {@link RedisCache} maps the given {@link byte[] key}
173-
* setting the {@link Duration TTL expiration} for the cache entry.
174+
* Asynchronously retrieves the {@link CompletableFuture value} to which the {@link RedisCache} maps
175+
* the given {@link byte[] key} setting the {@link Duration TTL expiration} for the cache entry.
174176
* <p>
175177
* This operation is non-blocking.
176178
*
@@ -260,10 +262,10 @@ interface TtlFunction {
260262
Duration NO_EXPIRATION = Duration.ZERO;
261263

262264
/**
263-
* Creates a singleton {@link TtlFunction} using the given {@link Duration}.
265+
* Creates a {@literal Singleton} {@link TtlFunction} using the given {@link Duration}.
264266
*
265-
* @param duration the time to live. Can be {@link Duration#ZERO} for persistent values (i.e. cache entry does not
266-
* expire).
267+
* @param duration the time to live. Can be {@link Duration#ZERO} for persistent values (i.e. cache entry
268+
* does not expire).
267269
* @return a singleton {@link TtlFunction} using {@link Duration}.
268270
*/
269271
static TtlFunction just(Duration duration) {

0 commit comments

Comments
 (0)
Please sign in to comment.