Class GemfireCacheManager
java.lang.Object
org.springframework.cache.support.AbstractCacheManager
org.springframework.data.gemfire.cache.GemfireCacheManager
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
,org.springframework.cache.CacheManager
public class GemfireCacheManager
extends org.springframework.cache.support.AbstractCacheManager
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.- See Also:
-
Cache
CacheManager
AbstractCacheManager
GemFireCache
Region
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.geode.cache.GemFireCache
getCache()
Returns theGemFireCache
instance backing thisCacheManager
.protected org.springframework.cache.Cache
getMissingCache
(String name) Returns a missing SpringCache
for the givenname
.protected Set<org.apache.geode.cache.Region<?,
?>> Returns the set of GemFireRegions
used explicitly as SpringCaches
in Spring's caching infrastructure.protected boolean
Determines whether thisCacheManager
allows the dynamic creation of aCache
at runtime.protected Collection<org.springframework.cache.Cache>
Loads all configured GemFireRegions
that will be used by thisCacheManager
.protected GemfireCache
newGemfireCache
(org.apache.geode.cache.Region<?, ?> region) Constructs a new instance ofGemfireCache
initialized with the given GemFireRegion
.void
setCache
(org.apache.geode.cache.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<org.apache.geode.cache.Region<?, ?>> regions) Explicitly sets the GemFireRegions
to be used as SpringCaches
in the application.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 classorg.springframework.cache.support.AbstractCacheManager
- 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:
-
Cache
-
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:
-
GemfireCache
Region
-
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 classorg.springframework.cache.support.AbstractCacheManager
- 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:
-
AbstractCacheManager.getMissingCache(String)
Cache
-
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
public void setCache(org.apache.geode.cache.GemFireCache gemfireCache) 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:
-
GemFireCache
-
getCache
protected org.apache.geode.cache.GemFireCache getCache()Returns theGemFireCache
instance backing thisCacheManager
.- Returns:
- the
GemFireCache
instance backing thisCacheManager
. - See Also:
-
GemFireCache
-
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:
-
Region
-
getRegions
Returns the set of GemFireRegions
used explicitly as SpringCaches
in Spring's caching infrastructure.- Returns:
- the set of GemFire
Regions
functioning as SpringCaches
in Spring's caching infrastructure - See Also:
-
Region
-