22
22
import java .util .LinkedList ;
23
23
import java .util .List ;
24
24
import java .util .Map ;
25
+ import java .util .Optional ;
25
26
import java .util .Set ;
26
27
27
28
import org .springframework .cache .transaction .AbstractTransactionSupportingCacheManager ;
@@ -352,10 +353,8 @@ public RedisCacheManagerBuilder initialCacheNames(Set<String> cacheNames) {
352
353
353
354
Assert .notNull (cacheNames , "CacheNames must not be null!" );
354
355
355
- Map <String , RedisCacheConfiguration > cacheConfigMap = new LinkedHashMap <>(cacheNames .size ());
356
- cacheNames .forEach (it -> cacheConfigMap .put (it , defaultCacheConfiguration ));
357
-
358
- return withInitialCacheConfigurations (cacheConfigMap );
356
+ cacheNames .forEach (it -> withCacheConfiguration (it , defaultCacheConfiguration ));
357
+ return this ;
359
358
}
360
359
361
360
/**
@@ -372,7 +371,22 @@ public RedisCacheManagerBuilder withInitialCacheConfigurations(
372
371
String .format ("RedisCacheConfiguration for cache %s must not be null!" , cacheName )));
373
372
374
373
this .initialCaches .putAll (cacheConfigurations );
374
+ return this ;
375
+ }
376
+
377
+ /**
378
+ * @param cacheName
379
+ * @param cacheConfiguration
380
+ * @return this {@link RedisCacheManagerBuilder}.
381
+ * @since 2.2
382
+ */
383
+ public RedisCacheManagerBuilder withCacheConfiguration (String cacheName ,
384
+ RedisCacheConfiguration cacheConfiguration ) {
375
385
386
+ Assert .notNull (cacheName , "CacheName must not be null!" );
387
+ Assert .notNull (cacheConfiguration , "CacheConfiguration must not be null!" );
388
+
389
+ this .initialCaches .put (cacheName , cacheConfiguration );
376
390
return this ;
377
391
}
378
392
@@ -392,6 +406,28 @@ public RedisCacheManagerBuilder disableCreateOnMissingCache() {
392
406
return this ;
393
407
}
394
408
409
+ /**
410
+ * Get the {@link Set} of cache names for which the builder holds {@link RedisCacheConfiguration configuration}.
411
+ *
412
+ * @return an unmodifiable {@link Set} holding the name of caches for which a {@link RedisCacheConfiguration
413
+ * configuration} has been set.
414
+ * @since 2.2
415
+ */
416
+ public Set <String > getConfiguredCaches () {
417
+ return Collections .unmodifiableSet (this .initialCaches .keySet ());
418
+ }
419
+
420
+ /**
421
+ * Get the {@link RedisCacheConfiguration} for a given cache by its name.
422
+ *
423
+ * @param cacheName must not be {@literal null}.
424
+ * @return {@link Optional#empty()} if no {@link RedisCacheConfiguration} set for the given cache name.
425
+ * @since 2.2
426
+ */
427
+ public Optional <RedisCacheConfiguration > getCacheConfigurationFor (String cacheName ) {
428
+ return Optional .ofNullable (this .initialCaches .get (cacheName ));
429
+ }
430
+
395
431
/**
396
432
* Create new instance of {@link RedisCacheManager} with configuration options applied.
397
433
*
0 commit comments