Skip to content

Commit 7cf67db

Browse files
committed
Add auto-configuration support for Apache Geode as a caching provider
Closes gh-6967
1 parent d0eedd2 commit 7cf67db

File tree

12 files changed

+424
-32
lines changed

12 files changed

+424
-32
lines changed

spring-boot-autoconfigure/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@
360360
</exclusion>
361361
</exclusions>
362362
</dependency>
363+
<dependency>
364+
<groupId>org.springframework.data</groupId>
365+
<artifactId>spring-data-geode</artifactId>
366+
<optional>true</optional>
367+
</dependency>
363368
<dependency>
364369
<groupId>org.springframework.data</groupId>
365370
<artifactId>spring-data-jpa</artifactId>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*
2828
* @author Phillip Webb
2929
* @author Eddú Meléndez
30+
* @author John Blum
3031
*/
3132
final class CacheConfigurations {
3233

@@ -42,6 +43,7 @@ final class CacheConfigurations {
4243
mappings.put(CacheType.COUCHBASE, CouchbaseCacheConfiguration.class);
4344
mappings.put(CacheType.REDIS, RedisCacheConfiguration.class);
4445
mappings.put(CacheType.CAFFEINE, CaffeineCacheConfiguration.class);
46+
mappings.put(CacheType.GEODE, GeodeCacheConfiguration.class);
4547
mappings.put(CacheType.SIMPLE, SimpleCacheConfiguration.class);
4648
mappings.put(CacheType.NONE, NoOpCacheConfiguration.class);
4749
MAPPINGS = Collections.unmodifiableMap(mappings);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @author Stephane Nicoll
2323
* @author Phillip Webb
2424
* @author Eddú Meléndez
25+
* @author John Blum
2526
* @since 1.3.0
2627
*/
2728
public enum CacheType {
@@ -67,13 +68,19 @@ public enum CacheType {
6768
CAFFEINE,
6869

6970
/**
71+
* Apache Geode backed caching.
72+
*/
73+
GEODE,
74+
75+
/**
76+
>>>>>>> Add auto-configuration support for Apache Geode as a caching provider.
7077
* Simple in-memory caching.
7178
*/
7279
SIMPLE,
7380

7481
/**
7582
* No caching.
7683
*/
77-
NONE;
84+
NONE
7885

7986
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2011-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.cache;
18+
19+
import java.util.HashSet;
20+
21+
import org.apache.geode.cache.Cache;
22+
import org.apache.geode.cache.GemFireCache;
23+
import org.apache.geode.cache.client.ClientCache;
24+
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
26+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
27+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
28+
import org.springframework.cache.CacheManager;
29+
import org.springframework.context.annotation.Bean;
30+
import org.springframework.context.annotation.Conditional;
31+
import org.springframework.context.annotation.Configuration;
32+
import org.springframework.data.gemfire.CacheFactoryBean;
33+
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
34+
import org.springframework.data.gemfire.support.GemfireCacheManager;
35+
36+
/**
37+
* GemFire cache configuration.
38+
*
39+
* @author John Blum
40+
* @see org.apache.geode.cache.Cache
41+
* @see org.apache.geode.cache.GemFireCache
42+
* @see org.apache.geode.cache.client.ClientCache
43+
* @see org.springframework.context.annotation.Bean
44+
* @see org.springframework.context.annotation.Configuration
45+
* @see org.springframework.data.gemfire.support.GemfireCacheManager
46+
* @since 1.5.0
47+
*/
48+
@Configuration
49+
@ConditionalOnBean({ CacheFactoryBean.class, Cache.class,
50+
ClientCacheFactoryBean.class, ClientCache.class })
51+
@ConditionalOnClass(GemfireCacheManager.class)
52+
@ConditionalOnMissingBean(CacheManager.class)
53+
@Conditional(CacheCondition.class)
54+
class GeodeCacheConfiguration {
55+
56+
private final CacheProperties cacheProperties;
57+
58+
private final CacheManagerCustomizers cacheManagerCustomizers;
59+
60+
GeodeCacheConfiguration(CacheProperties cacheProperties,
61+
CacheManagerCustomizers cacheManagerCustomizers) {
62+
63+
this.cacheProperties = cacheProperties;
64+
this.cacheManagerCustomizers = cacheManagerCustomizers;
65+
}
66+
67+
@Bean
68+
public GemfireCacheManager cacheManager(GemFireCache gemfireCache) {
69+
GemfireCacheManager cacheManager = new GemfireCacheManager();
70+
71+
cacheManager.setCache(gemfireCache);
72+
cacheManager.setCacheNames(new HashSet<String>(this.cacheProperties.getCacheNames()));
73+
74+
return this.cacheManagerCustomizers.customize(cacheManager);
75+
}
76+
}

0 commit comments

Comments
 (0)