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:
51
src/main/java/org/springframework/data/gemfire/cache/config/EnableGemfireCaching.java
vendored
Normal file
51
src/main/java/org/springframework/data/gemfire/cache/config/EnableGemfireCaching.java
vendored
Normal 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 {
|
||||
|
||||
}
|
||||
66
src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java
vendored
Normal file
66
src/main/java/org/springframework/data/gemfire/cache/config/GemfireCachingConfiguration.java
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user