SGF-645 - Add Annotation to configure and enable the Spring Cache Abstraction with the GemfireCacheManager.

(cherry picked from commit 8520b1bd570935be18c04cbb9190fe7c1eb54a06)
Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
John Blum
2017-07-19 18:04:19 -07:00
parent b6e51e807f
commit b554458fd7
3 changed files with 271 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.cache.config;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
/**
* The {@link EnableGemfireCaching} annotation enables Pivotal GemFire or Apache Geode as a caching provider
* in Spring's Cache Abstraction.
*
* @author John Blum
* @see java.lang.annotation.Documented
* @see java.lang.annotation.Inherited
* @see java.lang.annotation.Retention
* @see java.lang.annotation.Target
* @see org.springframework.context.annotation.Import
* @see <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cache">Cache Abstraction</a>
* @see <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cache-store-configuration-gemfire">GemFire-based Cache</a>
* @see <a href="http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/#apis:spring-cache-abstraction">Support for Spring Cache Abstraction</a>
* @since 2.0.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Import(GemfireCachingConfiguration.class)
@SuppressWarnings("unused")
public @interface EnableGemfireCaching {
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.cache.config;
import org.apache.geode.cache.GemFireCache;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.cache.GemfireCacheManager;
/**
* The {@link GemfireCachingConfiguration} class is a Spring {@link Configuration @Configuration} class
* used to configure Pivotal GemFire or Apache Geode as the caching provider in Spring's Cache Abstraction.
*
* Additionally, this Spring {@link Configuration} class also enables the Spring Cache Abstraction
* with {@link EnableCaching}.
*
* @author John Blum
* @see org.apache.geode.cache.GemFireCache
* @see org.springframework.cache.annotation.EnableCaching
* @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.data.gemfire.cache.GemfireCacheManager
* @see org.springframework.data.gemfire.cache.config.EnableGemfireCaching
* @see <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cache">Cache Abstraction</a>
* @see <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cache-store-configuration-gemfire">GemFire-based Cache</a>
* @see <a href="http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/#apis:spring-cache-abstraction">Support for Spring Cache Abstraction</a>
* @since 2.0.0
*/
@Configuration
@EnableCaching
@SuppressWarnings("unused")
public class GemfireCachingConfiguration {
/**
* SDG's {@link GemfireCacheManager} used to position Pivotal GemFire or Apache Geode as the caching provider
* in Spring's Cache Abstraction.
*
* @return an instance of {@link GemfireCacheManager}.
* @see org.springframework.data.gemfire.cache.GemfireCacheManager
* @see org.apache.geode.cache.GemFireCache
*/
@Bean
public GemfireCacheManager cacheManager(GemFireCache gemfireCache) {
GemfireCacheManager gemfireCacheManager = new GemfireCacheManager();
gemfireCacheManager.setCache(gemfireCache);
return gemfireCacheManager;
}
}