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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.apache.geode.cache.GemFireCache
    Returns the GemFireCache instance backing this CacheManager.
    protected org.springframework.cache.Cache
    Returns a missing Spring Cache for the given name.
    protected Set<org.apache.geode.cache.Region<?,?>>
    Returns the set of GemFire Regions used explicitly as Spring Caches in Spring's caching infrastructure.
    protected boolean
    Determines whether this CacheManager allows the dynamic creation of a Cache at runtime.
    protected Collection<org.springframework.cache.Cache>
    Loads all configured GemFire Regions that will be used by this CacheManager.
    protected GemfireCache
    newGemfireCache(org.apache.geode.cache.Region<?,?> region)
    Constructs a new instance of GemfireCache initialized with the given GemFire Region.
    void
    setCache(org.apache.geode.cache.GemFireCache gemfireCache)
    Sets the GemFire cache instance backing this CacheManager.
    void
    setCacheNames(Set<String> cacheNames)
    Sets the names of all Spring Caches that will be used in the application.
    void
    setRegions(Set<org.apache.geode.cache.Region<?,?>> regions)
    Explicitly sets the GemFire Regions to be used as Spring Caches in the application.

    Methods inherited from class org.springframework.cache.support.AbstractCacheManager

    afterPropertiesSet, decorateCache, getCache, getCacheNames, initializeCaches, lookupCache

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GemfireCacheManager

      public GemfireCacheManager()
  • Method Details

    • loadCaches

      protected Collection<org.springframework.cache.Cache> loadCaches()
      Loads all configured GemFire Regions that will be used by this CacheManager. Any GemFire Regions configured with the regions property will take precedence over any configured cacheNames. If no GemFire Regions were configured, then any cacheNames that were specified will be used to lookup existing GemFire Regions to function as Spring Cachesin Spring's caching infrastructure. However, if neither regions nor cacheNames were specified, then all defined GemFire Regions declared in the Spring application context, as determined by RegionService.rootRegions(), will be used as Spring Caches, and this CacheManager will allow any dynamically created GemFire Regions at runtime to be found and used as a Spring Cache as well.
      Specified by:
      loadCaches in class org.springframework.cache.support.AbstractCacheManager
      Returns:
      a Collection of GemFire Regions used by this CacheManager to function as Caches in Spring's caching infrastructure.
      Throws:
      IllegalStateException - if a GemFire cache instance was not provided, the provided GemFire cache instance has been closed, no GemFire Region could be found for a given cache name, or the GemFire Region for the given cache name has been destroyed.
      See Also:
      • Cache
    • newGemfireCache

      protected GemfireCache newGemfireCache(org.apache.geode.cache.Region<?,?> region)
      Constructs a new instance of GemfireCache initialized with the given GemFire Region.
      Parameters:
      region - GemFire Region to wrap (adapt).
      Returns:
      an instance of GemfireCache initialized with the given GemFire Region.
      See Also:
    • getMissingCache

      protected org.springframework.cache.Cache getMissingCache(String name)
      Returns a missing Spring Cache for the given name. To return a missing Spring Cache for the given name, dynamic cache lookup/creation must be enabled, which means that either the cacheNames or regions properties must not be set. If either property was specified then dynamic Spring Cache lookup/creation will be disabled and this overridden AbstractCacheManager.getMissingCache(String) method will return null.
      Overrides:
      getMissingCache in class org.springframework.cache.support.AbstractCacheManager
      Parameters:
      name - name of the missing Spring Cache to lookup (and potentially create).
      Returns:
      a Spring Cache instance for the given name or null if the Cache cannot be found (or possibly created).
      See Also:
      • AbstractCacheManager.getMissingCache(String)
      • Cache
    • isDynamic

      protected boolean isDynamic()
      Determines whether this CacheManager allows the dynamic creation of a Cache 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 this CacheManager. When set, if neither Regions nor cacheNames were specified, then this CacheManager is capable of creating Spring Caches backed by existing GemFire Regions used by the application at runtime. However, in order to dynamically create Spring Caches a reference to an open GemFire cache instance must be set.
      Parameters:
      gemfireCache - the GemFire cache instance used by this CacheManager to manage Spring Caches.
      See Also:
      • GemFireCache
    • getCache

      protected org.apache.geode.cache.GemFireCache getCache()
      Returns the GemFireCache instance backing this CacheManager.
      Returns:
      the GemFireCache instance backing this CacheManager.
      See Also:
      • GemFireCache
    • setCacheNames

      public void setCacheNames(Set<String> cacheNames)
      Sets the names of all Spring Caches that will be used in the application. When set, this disables the dynamic capability of this CacheManager to create Spring Caches at runtime by dynamically looking up existing Regions from the GemFire cache instance.
      Parameters:
      cacheNames - Set of cache names that will be used in the application.
      See Also:
    • setRegions

      public void setRegions(Set<org.apache.geode.cache.Region<?,?>> regions)
      Explicitly sets the GemFire Regions to be used as Spring Caches in the application. When set, this disables the dynamic capability of this CacheManager to create Spring Caches at runtime by dynamically looking up existing Regions from the GemFire cache instance.
      Parameters:
      regions - Set of GemFire Regions used by this CacheManager as Spring Caches.
      See Also:
      • Region
    • getRegions

      protected Set<org.apache.geode.cache.Region<?,?>> getRegions()
      Returns the set of GemFire Regions used explicitly as Spring Caches in Spring's caching infrastructure.
      Returns:
      the set of GemFire Regions functioning as Spring Caches in Spring's caching infrastructure
      See Also:
      • Region