Skip to content

Commit c5d4123

Browse files
committed
Merge pull request #25321 from sdeleuze
* pr/25321: Refactor CacheConfigurations to avoid storing configuration classes Closes gh-25321
2 parents b5e1787 + 512efa1 commit c5d4123

File tree

1 file changed

+19
-18
lines changed
  • spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache

1 file changed

+19
-18
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheConfigurations.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,39 +27,40 @@
2727
*
2828
* @author Phillip Webb
2929
* @author Eddú Meléndez
30+
* @author Sebastien Deleuze
3031
*/
3132
@SuppressWarnings("deprecation")
3233
final class CacheConfigurations {
3334

34-
private static final Map<CacheType, Class<?>> MAPPINGS;
35+
private static final Map<CacheType, String> MAPPINGS;
3536

3637
static {
37-
Map<CacheType, Class<?>> mappings = new EnumMap<>(CacheType.class);
38-
mappings.put(CacheType.GENERIC, GenericCacheConfiguration.class);
39-
mappings.put(CacheType.EHCACHE, EhCacheCacheConfiguration.class);
40-
mappings.put(CacheType.HAZELCAST, HazelcastCacheConfiguration.class);
41-
mappings.put(CacheType.INFINISPAN, InfinispanCacheConfiguration.class);
42-
mappings.put(CacheType.JCACHE, JCacheCacheConfiguration.class);
43-
mappings.put(CacheType.COUCHBASE, CouchbaseCacheConfiguration.class);
44-
mappings.put(CacheType.REDIS, RedisCacheConfiguration.class);
45-
mappings.put(CacheType.CAFFEINE, CaffeineCacheConfiguration.class);
46-
mappings.put(CacheType.SIMPLE, SimpleCacheConfiguration.class);
47-
mappings.put(CacheType.NONE, NoOpCacheConfiguration.class);
38+
Map<CacheType, String> mappings = new EnumMap<>(CacheType.class);
39+
mappings.put(CacheType.GENERIC, GenericCacheConfiguration.class.getName());
40+
mappings.put(CacheType.EHCACHE, EhCacheCacheConfiguration.class.getName());
41+
mappings.put(CacheType.HAZELCAST, HazelcastCacheConfiguration.class.getName());
42+
mappings.put(CacheType.INFINISPAN, InfinispanCacheConfiguration.class.getName());
43+
mappings.put(CacheType.JCACHE, JCacheCacheConfiguration.class.getName());
44+
mappings.put(CacheType.COUCHBASE, CouchbaseCacheConfiguration.class.getName());
45+
mappings.put(CacheType.REDIS, RedisCacheConfiguration.class.getName());
46+
mappings.put(CacheType.CAFFEINE, CaffeineCacheConfiguration.class.getName());
47+
mappings.put(CacheType.SIMPLE, SimpleCacheConfiguration.class.getName());
48+
mappings.put(CacheType.NONE, NoOpCacheConfiguration.class.getName());
4849
MAPPINGS = Collections.unmodifiableMap(mappings);
4950
}
5051

5152
private CacheConfigurations() {
5253
}
5354

5455
static String getConfigurationClass(CacheType cacheType) {
55-
Class<?> configurationClass = MAPPINGS.get(cacheType);
56-
Assert.state(configurationClass != null, () -> "Unknown cache type " + cacheType);
57-
return configurationClass.getName();
56+
String configurationClassName = MAPPINGS.get(cacheType);
57+
Assert.state(configurationClassName != null, () -> "Unknown cache type " + cacheType);
58+
return configurationClassName;
5859
}
5960

6061
static CacheType getType(String configurationClassName) {
61-
for (Map.Entry<CacheType, Class<?>> entry : MAPPINGS.entrySet()) {
62-
if (entry.getValue().getName().equals(configurationClassName)) {
62+
for (Map.Entry<CacheType, String> entry : MAPPINGS.entrySet()) {
63+
if (entry.getValue().equals(configurationClassName)) {
6364
return entry.getKey();
6465
}
6566
}

0 commit comments

Comments
 (0)