Class GemfireCache

java.lang.Object
org.springframework.data.gemfire.cache.GemfireCache
All Implemented Interfaces:
org.springframework.cache.Cache

public class GemfireCache extends Object implements org.springframework.cache.Cache
Spring Framework Cache implementation backed by a GemFire Region.
See Also:
  • Cache
  • Region
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.cache.Cache

    org.springframework.cache.Cache.ValueRetrievalException, org.springframework.cache.Cache.ValueWrapper
  • Constructor Summary

    Constructors
    Constructor
    Description
    GemfireCache(org.apache.geode.cache.Region<?,?> region)
    Constructs an instance of GemFireCache initialized with the given GemFire Region.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the entire contents of this Spring Cache.
    void
    Evicts (destroys) the entry (key/value) mapped to the given key from this Spring Cache.
    org.springframework.cache.Cache.ValueWrapper
    get(Object key)
    Returns the cache value for the given key wrapped in an instance of Cache.ValueWrapper.
    <T> T
    get(Object key, Class<T> type)
    Returns the cache value for the given key cast to the specified Class type.
    <T> T
    get(Object key, Callable<T> valueLoader)
    Returns the cache value for given key.
    Returns the name of this Spring Cache.
    org.apache.geode.cache.Region
    Returns the GemFire Region used as the implementation for this Spring Cache.
    void
    put(Object key, Object value)
    Stores the given value in the cache referenced by the given key.
    org.springframework.cache.Cache.ValueWrapper
    putIfAbsent(Object key, Object value)
    Implementation of Cache.putIfAbsent(Object, Object) satisfying the extension of the Cache interface in Spring 4.1.
    wrap(org.apache.geode.cache.Region<?,?> region)
    Wraps a GemFire Region in an instance of GemfireCache to adapt the GemFire Region to function as a Spring Cache in Spring's caching infrastructure.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.cache.Cache

    evictIfPresent, invalidate
  • Constructor Details

    • GemfireCache

      public GemfireCache(org.apache.geode.cache.Region<?,?> region)
      Constructs an instance of GemFireCache initialized with the given GemFire Region. The Region will function as the backing store and implementation for the Spring Cache interface.
      Parameters:
      region - GemFire Region backing the Spring Cache.
      Throws:
      IllegalArgumentException - if Region is null.
  • Method Details

    • wrap

      public static GemfireCache wrap(org.apache.geode.cache.Region<?,?> region)
      Wraps a GemFire Region in an instance of GemfireCache to adapt the GemFire Region to function as a Spring Cache in Spring's caching infrastructure.
      Parameters:
      region - GemFire Region to wrap.
      Returns:
      an instance of GemfireCache backed by the provided GemFire Region.
      See Also:
    • getNativeCache

      public org.apache.geode.cache.Region getNativeCache()
      Returns the GemFire Region used as the implementation for this Spring Cache.
      Specified by:
      getNativeCache in interface org.springframework.cache.Cache
      Returns:
      the GemFire Region used as the implementation for this Spring Cache.
      See Also:
      • Region
    • getName

      public String getName()
      Returns the name of this Spring Cache.
      Specified by:
      getName in interface org.springframework.cache.Cache
      Returns:
      the name of this Spring Cache.
      See Also:
      • Region.getName()
    • clear

      public void clear()
      Clears the entire contents of this Spring Cache.
      Specified by:
      clear in interface org.springframework.cache.Cache
      See Also:
      • Region.clear()
    • evict

      public void evict(Object key)
      Evicts (destroys) the entry (key/value) mapped to the given key from this Spring Cache.
      Specified by:
      evict in interface org.springframework.cache.Cache
      Parameters:
      key - key used to identify the cache entry to evict.
      See Also:
      • Region.destroy(Object)
    • get

      public org.springframework.cache.Cache.ValueWrapper get(Object key)
      Returns the cache value for the given key wrapped in an instance of Cache.ValueWrapper.
      Specified by:
      get in interface org.springframework.cache.Cache
      Parameters:
      key - key identifying the the value to retrieve from the cache.
      Returns:
      the value cached with the given key.
      See Also:
      • Cache.ValueWrapper
      • Region.get(Object)
    • get

      public <T> T get(Object key, Class<T> type)
      Returns the cache value for the given key cast to the specified Class type.
      Specified by:
      get in interface org.springframework.cache.Cache
      Type Parameters:
      T - desired Class type of the cache value.
      Parameters:
      key - key identifying the the value to retrieve from the cache.
      type - desired Class type of the value.
      Returns:
      the cache value for the given key cast to the specified Class type.
      Throws:
      IllegalStateException - if the value is not null and not an instance of the desired type.
      See Also:
      • Region.get(Object)
    • get

      public <T> T get(Object key, Callable<T> valueLoader)
      Returns the cache value for given key. If the value is null, then the provided Callable valueLoader will be called to obtain a value and add the entry to this cache.
      Specified by:
      get in interface org.springframework.cache.Cache
      Type Parameters:
      T - Class type of the value.
      Parameters:
      key - key identifying the the value to retrieve from the cache.
      valueLoader - Callable object used to load a value if the entry identified by the key does not already have value.
      Returns:
      the cache value of the given key or a value obtained by calling the Callable object if the value for key is null.
      Throws:
      org.springframework.cache.Cache.ValueRetrievalException - if an error occurs while trying to load a value for given key using the Callable.
      See Also:
    • put

      public void put(Object key, Object value)
      Stores the given value in the cache referenced by the given key. This operation will only store the value if the value is not null.
      Specified by:
      put in interface org.springframework.cache.Cache
      Parameters:
      key - key used to reference the value in the cache.
      value - value to store in the cache referenced by the key.
      See Also:
      • Region.put(Object, Object)
    • putIfAbsent

      public org.springframework.cache.Cache.ValueWrapper putIfAbsent(Object key, Object value)
      Implementation of Cache.putIfAbsent(Object, Object) satisfying the extension of the Cache interface in Spring 4.1. Don't add the Override annotation otherwise this will break the compilation on 4.0.
      Specified by:
      putIfAbsent in interface org.springframework.cache.Cache
      Returns:
      the existing value if the given key is already mapped to a value.
      See Also:
      • Cache.putIfAbsent(Object, Object)
      • Region.putIfAbsent(Object, Object)