Class GemfireCacheManager
java.lang.Object
org.springframework.cache.support.AbstractCacheManager
org.springframework.data.gemfire.cache.GemfireCacheManager
- All Implemented Interfaces:
InitializingBean,CacheManager
Core Spring Framework
CacheManager implementation backed by a GemFire cache instance
(either a client or peer cache).
Automatically discovers available caches (or GemFire Regions) when a cache for a given name
is missing and dynamic cache lookup/creation is enabled.- Author:
- Costin Leau, David Turanski, John Blum
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected GemFireCachegetCache()Returns theGemFireCacheinstance backing thisCacheManager.protected CachegetMissingCache(String name) Returns a missing SpringCachefor the givenname.protected booleanDetermines whether thisCacheManagerallows the dynamic creation of aCacheat runtime.protected Collection<Cache>Loads all configured GemFireRegionsthat will be used by thisCacheManager.protected GemfireCachenewGemfireCache(Region<?, ?> region) Constructs a new instance ofGemfireCacheinitialized with the given GemFireRegion.voidsetCache(GemFireCache gemfireCache) Sets the GemFire cache instance backing thisCacheManager.voidsetCacheNames(Set<String> cacheNames) Sets the names of all SpringCachesthat will be used in the application.voidsetRegions(Set<Region<?, ?>> regions) Methods inherited from class org.springframework.cache.support.AbstractCacheManager
afterPropertiesSet, decorateCache, getCache, getCacheNames, initializeCaches, lookupCache
-
Constructor Details
-
GemfireCacheManager
public GemfireCacheManager()
-
-
Method Details
-
loadCaches
Loads all configured GemFireRegionsthat will be used by thisCacheManager. Any GemFireRegionsconfigured with theregionsproperty will take precedence over any configuredcacheNames. If no GemFireRegionswere configured, then anycacheNamesthat were specified will be used to lookup existing GemFireRegionsto function as SpringCachesin Spring's caching infrastructure. However, if neitherregionsnorcacheNameswere specified, then all defined GemFireRegionsdeclared in the Spring application context, as determined byRegionService.rootRegions(), will be used as SpringCaches, and thisCacheManagerwill allow any dynamically created GemFireRegionsat runtime to be found and used as a SpringCacheas well.- Specified by:
loadCachesin classAbstractCacheManager- Returns:
- a
Collectionof GemFireRegionsused by thisCacheManagerto function asCachesin Spring's caching infrastructure. - Throws:
IllegalStateException- if a GemFire cache instance was not provided, the provided GemFire cache instance has been closed, no GemFireRegioncould be found for a given cache name, or the GemFireRegionfor the given cache name has been destroyed.- See Also:
-
newGemfireCache
Constructs a new instance ofGemfireCacheinitialized with the given GemFireRegion.- Parameters:
region- GemFireRegionto wrap (adapt).- Returns:
- an instance of
GemfireCacheinitialized with the given GemFireRegion. - See Also:
-
getMissingCache
Returns a missing SpringCachefor the givenname. To return a missing SpringCachefor the givenname, dynamic cache lookup/creation must be enabled, which means that either thecacheNamesorregionsproperties must not be set. If either property was specified then dynamic SpringCachelookup/creation will be disabled and this overriddenAbstractCacheManager.getMissingCache(String)method will return null.- Overrides:
getMissingCachein classAbstractCacheManager- Parameters:
name- name of the missing SpringCacheto lookup (and potentially create).- Returns:
- a Spring
Cacheinstance for the givennameor null if theCachecannot be found (or possibly created). - See Also:
-
isDynamic
protected boolean isDynamic()Determines whether thisCacheManagerallows the dynamic creation of aCacheat runtime.- Returns:
- a boolean value indicating whether dynamic
Cachecreation is enabled.
-
setCache
Sets the GemFire cache instance backing thisCacheManager. When set, if neitherRegionsnorcacheNameswere specified, then thisCacheManageris capable of creating SpringCachesbacked by existing GemFireRegionsused by the application at runtime. However, in order to dynamically create SpringCachesa reference to an open GemFire cache instance must be set.- Parameters:
gemfireCache- the GemFire cache instance used by thisCacheManagerto manage SpringCaches.- See Also:
-
getCache
Returns theGemFireCacheinstance backing thisCacheManager.- Returns:
- the
GemFireCacheinstance backing thisCacheManager. - See Also:
-
setCacheNames
Sets the names of all SpringCachesthat will be used in the application. When set, this disables the dynamic capability of thisCacheManagerto create SpringCachesat runtime by dynamically looking up existingRegionsfrom the GemFire cache instance. -
setRegions
Explicitly sets the GemFireRegionsto be used as SpringCachesin the application. When set, this disables the dynamic capability of thisCacheManagerto create SpringCachesat runtime by dynamically looking up existingRegionsfrom the GemFire cache instance.- Parameters:
regions-Setof GemFireRegionsused by thisCacheManageras SpringCaches.- See Also:
-
getRegions
-