Class GemfireCacheManager

java.lang.Object
org.springframework.cache.support.AbstractCacheManager
org.springframework.data.gemfire.cache.GemfireCacheManager
All Implemented Interfaces:
InitializingBean, CacheManager

public class GemfireCacheManager extends 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.
Author:
Costin Leau, David Turanski, John Blum
See Also:
  • Constructor Details

    • GemfireCacheManager

      public GemfireCacheManager()
  • Method Details

    • loadCaches

      protected Collection<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 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:
    • newGemfireCache

      protected GemfireCache newGemfireCache(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 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 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:
    • 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(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:
    • getCache

      protected GemFireCache getCache()
      Returns the GemFireCache instance backing this CacheManager.
      Returns:
      the GemFireCache instance backing this CacheManager.
      See Also:
    • 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<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:
    • getRegions

      protected Set<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: