CacheLoader (Apache Geode 1.11.0)
Date: 2019-12-20

org.apache.geode.cache

## Interface CacheLoader<K,V>

- All Superinterfaces:
    CacheCallback, Declarable
  All Known Implementing Classes:
    JdbcLoader, LocalSessionCacheLoader

      public interface CacheLoader<K,V>
      extends CacheCallback

  Allows data from outside of the VM to be placed into a region. When `Region.get(Object)` is called for a region entry that has a `null` value, the `load` method of the region's cache loader is invoked. The `load` method creates the value for the desired key by performing an operation such as a database query. The `load` may also perform a net search that will look for the value in a cache instance hosted by another member of the distributed system.

  WARNING: To avoid risk of deadlock, do not invoke CacheFactory.getAnyInstance() from within any callback methods. Instead use LoaderHelper.getRegion().getCache().

  Since:
    GemFire 2.0
  See Also:
    `AttributesFactory.setCacheLoader(org.apache.geode.cache.CacheLoader<K, V>)`, `RegionAttributes.getCacheLoader()`, `AttributesMutator.setCacheLoader(org.apache.geode.cache.CacheLoader<K, V>)`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `V` | `load(LoaderHelper<K,V> helper)` Loads a value.

    - ### Methods inherited from interface org.apache.geode.cache.CacheCallback

      `close`

    - ### Methods inherited from interface org.apache.geode.cache.Declarable

      `init, initialize`

- - ### Method Detail

    - #### load

          V load(LoaderHelper<K,V> helper)
          throws CacheLoaderException

      Loads a value. Application writers should implement this method to customize the loading of a value. This method is called by the caching service when the requested value is not in the cache. Any exception (including an unchecked exception) thrown by this method is propagated back to and thrown by the invocation of `Region.get(Object, Object)` that triggered this load.

      Parameters:
        `helper` - a LoaderHelper object that is passed in from cache service and provides access to the key, region, argument, and `netSearch`.
      Returns:
        the value supplied for this key, or null if no value can be supplied. A local loader will always be invoked if one exists. Otherwise one remote loader is invoked. Returning `null` causes `Region.get(Object, Object)` to return `null`.
      Throws:
        `CacheLoaderException,` - if an error occurs. This exception or any other exception thrown by this method will be propagated back to the application from the get method.
        `CacheLoaderException`
      See Also:
        `Region.get`