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
-
Method Summary
Modifier and TypeMethodDescriptionprotected GemFireCache
getCache()
Returns theGemFireCache
instance backing thisCacheManager
.protected Cache
getMissingCache
(String name) Returns a missing SpringCache
for the givenname
.protected boolean
Determines whether thisCacheManager
allows the dynamic creation of aCache
at runtime.protected Collection<Cache>
Loads all configured GemFireRegions
that will be used by thisCacheManager
.protected GemfireCache
newGemfireCache
(Region<?, ?> region) Constructs a new instance ofGemfireCache
initialized with the given GemFireRegion
.void
setCache
(GemFireCache gemfireCache) Sets the GemFire cache instance backing thisCacheManager
.void
setCacheNames
(Set<String> cacheNames) Sets the names of all SpringCaches
that will be used in the application.void
setRegions
(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 GemFireRegions
that will be used by thisCacheManager
. Any GemFireRegions
configured with theregions
property will take precedence over any configuredcacheNames
. If no GemFireRegions
were configured, then anycacheNames
that were specified will be used to lookup existing GemFireRegions
to function as SpringCaches
in Spring's caching infrastructure. However, if neitherregions
norcacheNames
were specified, then all defined GemFireRegions
declared in the Spring application context, as determined byRegionService.rootRegions()
, will be used as SpringCaches
, and thisCacheManager
will allow any dynamically created GemFireRegions
at runtime to be found and used as a SpringCache
as well.- Specified by:
loadCaches
in classAbstractCacheManager
- Returns:
- a
Collection
of GemFireRegions
used by thisCacheManager
to function asCaches
in Spring's caching infrastructure. - Throws:
IllegalStateException
- if a GemFire cache instance was not provided, the provided GemFire cache instance has been closed, no GemFireRegion
could be found for a given cache name, or the GemFireRegion
for the given cache name has been destroyed.- See Also:
-
newGemfireCache
Constructs a new instance ofGemfireCache
initialized with the given GemFireRegion
.- Parameters:
region
- GemFireRegion
to wrap (adapt).- Returns:
- an instance of
GemfireCache
initialized with the given GemFireRegion
. - See Also:
-
getMissingCache
Returns a missing SpringCache
for the givenname
. To return a missing SpringCache
for the givenname
, dynamic cache lookup/creation must be enabled, which means that either thecacheNames
orregions
properties must not be set. If either property was specified then dynamic SpringCache
lookup/creation will be disabled and this overriddenAbstractCacheManager.getMissingCache(String)
method will return null.- Overrides:
getMissingCache
in classAbstractCacheManager
- Parameters:
name
- name of the missing SpringCache
to lookup (and potentially create).- Returns:
- a Spring
Cache
instance for the givenname
or null if theCache
cannot be found (or possibly created). - See Also:
-
isDynamic
protected boolean isDynamic()Determines whether thisCacheManager
allows the dynamic creation of aCache
at runtime.- Returns:
- a boolean value indicating whether dynamic
Cache
creation is enabled.
-
setCache
Sets the GemFire cache instance backing thisCacheManager
. When set, if neitherRegions
norcacheNames
were specified, then thisCacheManager
is capable of creating SpringCaches
backed by existing GemFireRegions
used by the application at runtime. However, in order to dynamically create SpringCaches
a reference to an open GemFire cache instance must be set.- Parameters:
gemfireCache
- the GemFire cache instance used by thisCacheManager
to manage SpringCaches
.- See Also:
-
getCache
Returns theGemFireCache
instance backing thisCacheManager
.- Returns:
- the
GemFireCache
instance backing thisCacheManager
. - See Also:
-
setCacheNames
Sets the names of all SpringCaches
that will be used in the application. When set, this disables the dynamic capability of thisCacheManager
to create SpringCaches
at runtime by dynamically looking up existingRegions
from the GemFire cache instance. -
setRegions
Explicitly sets the GemFireRegions
to be used as SpringCaches
in the application. When set, this disables the dynamic capability of thisCacheManager
to create SpringCaches
at runtime by dynamically looking up existingRegions
from the GemFire cache instance.- Parameters:
regions
-Set
of GemFireRegions
used by thisCacheManager
as SpringCaches
.- See Also:
-
getRegions
-