gemfire::CacheLoader Class Reference

Inherits gemfire::SharedBase.


Detailed Description

An application plug-in that can be installed on a region.

Loaders facilitate loading of data into the cache. When an application does a lookup for a key in a region and it does not exist, the system checks to see if any loaders are available for the region in the system and invokes them to get the value for the key into the cache. Allows data to be loaded from a 3rd party data source and placed into the region When Region::get is called for a region entry that has a null value, the CacheLoader::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 netSearch and netLoad that looks for the value in a cache instance hosted by another member of the distributed system

See also:
AttributesFactory::setCacheLoader

RegionAttributes::getCacheLoader


Public Member Functions

virtual void close (const RegionPtr &rp)
 Called when the region containing this callback is destroyed, when the cache is closed.
virtual CacheablePtr load (const RegionPtr &rp, const CacheableKeyPtr &key, UserDataPtr &helper)=0
 Loads a value.
void preserveSB () const
 Atomically increment reference count.
int32_t refCount ()
 
Returns:
the reference count

void releaseSB () const
 Atomically decrement reference count, the SharedBase object is automatically deleted when its reference count goes to zero.

Static Public Member Functions

static CacheablePtr netSearch (const RegionPtr &rp, const CacheableKeyPtr &keyPtr, bool netLoad, UserDataPtr &cacheLoaderParam)
 Searches other caches for the value to be loaded.

Member Function Documentation

virtual void gemfire::CacheLoader::close ( const RegionPtr rp  )  [virtual]

Called when the region containing this callback is destroyed, when the cache is closed.

Implementations should clean up any external resources, such as database connections. Any runtime exceptions this method throws will be logged.

It is possible for this method to be called multiple times on a single callback instance, so implementations must be tolerant of this.

Parameters:
rp the region pointer
See also:
Cache::close

Region::destroyRegion

virtual CacheablePtr gemfire::CacheLoader::load ( const RegionPtr rp,
const CacheableKeyPtr key,
UserDataPtr helper 
) [pure virtual]

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 thrown by this method is propagated back to and thrown by the invocation of Region::get that triggered this load.

Parameters:
rp a Region Pointer for which this is called.
key the key for the cacheable
helper any related user data, or null
Returns:
the value supplied for this key, or null if no value can be supplied. If this load is invoked as part of a netSearch, returning null will cause GemFire to invoke the next loader it finds in the system (if there is one). If every available loader returns a null value, Region::get will return null.
See also:
Region::get .

static CacheablePtr gemfire::CacheLoader::netSearch ( const RegionPtr rp,
const CacheableKeyPtr keyPtr,
bool  netLoad,
UserDataPtr cacheLoaderParam 
) [static]

Searches other caches for the value to be loaded.

If the cache is part of a distributed caching system, netSearch will try to locate the requested value in any other cache within the system. If the search is successful, a reference to a local copy of the value is returned. If there is no value for this entry locally, and doNetLoad is true, GemFire looks for and invokes CacheLoaders in other nodes in the system. The net load will invoke one loader at a time until a loader either returns a non-null value or throws an exception. If the object is not found, NULL is returned.

Parameters:
rp a pointer to the region to do the netsearch on
keyPtr a pointer to the key to do the netsearch for
netLoad if true, and there is no valid value found for this entry in the local system, then look for and invoke loaders on other nodes
cacheLoaderParam passed to netloader if netLoad is set to true
Returns:
The value found by the netSearch operation, or NULL if nothing was found.

void gemfire::SharedBase::preserveSB (  )  const [inherited]

Atomically increment reference count.

int32_t gemfire::SharedBase::refCount (  )  [inline, inherited]

Returns:
the reference count

void gemfire::SharedBase::releaseSB (  )  const [inherited]

Atomically decrement reference count, the SharedBase object is automatically deleted when its reference count goes to zero.


GemFire C++ Cache API Documentation