org.ehcache.spi.loaderwriter
Interface CacheLoaderWriter<K,V>

Type Parameters:
K - the type of the keys used to access data within the cache
V - the type of the values held within the cache
All Known Subinterfaces:
WriteBehind<K,V>
All Known Implementing Classes:
BatchingLocalHeapWriteBehindQueue, NonBatchingLocalHeapWriteBehindQueue, StripedWriteBehind

public interface CacheLoaderWriter<K,V>

A CacheLoaderWriter is associated with a given Cache instance and will be used to keep it in sync with another system.

Instances of this class have to be thread safe.

Any Exception thrown by the loading methods of this interface will be wrapped into a CacheLoadingException by the Cache and will need to be handled by the user. Any java.lang.Exception thrown by the writing methods will be wrapped into a CacheWritingException.

See Also:
CacheLoadingException, CacheWritingException

Method Summary
 void delete(K key)
          Deletes a single entry from the underlying system of record.
 void deleteAll(java.lang.Iterable<? extends K> keys)
          Deletes a set of entry from the underlying system of record.
 V load(K key)
          Loads the value to be associated with the given key in the Cache using this CacheLoaderWriter instance.
 java.util.Map<K,V> loadAll(java.lang.Iterable<? extends K> keys)
          Loads the values to be associated with the keys in the Cache using this CacheLoaderWriter instance.
 void write(K key, V value)
          Writes a single entry to the underlying system of record, maybe a brand new value or an update to an existing value
 void writeAll(java.lang.Iterable<? extends java.util.Map.Entry<? extends K,? extends V>> entries)
          Writes multiple entries to the underlying system of record.
 

Method Detail

load

V load(K key)
       throws java.lang.Exception
Loads the value to be associated with the given key in the Cache using this CacheLoaderWriter instance.

Parameters:
key - the key that will map to the value returned
Returns:
the value to be mapped
Throws:
java.lang.Exception - if the value cannot be loaded

loadAll

java.util.Map<K,V> loadAll(java.lang.Iterable<? extends K> keys)
                           throws java.lang.Exception
Loads the values to be associated with the keys in the Cache using this CacheLoaderWriter instance. The returned Map should contain null mapped keys for values that couldn't be found.
The mapping that will be installed in the cache is the key as found in the input parameter keys mapped to the result of loadAllResult.get(key). Any other mapping will be ignored.

Parameters:
keys - the keys that will be mapped to the values returned in the map
Returns:
the Map of values for each key passed in, where no mapping means no value to map.
Throws:
BulkCacheLoadingException - This writer must throw this exception to indicate partial success. The exception declares which keys were actually loaded (if any)
java.lang.Exception - a generic failure. All values will be considered not loaded in this case

write

void write(K key,
           V value)
           throws java.lang.Exception
Writes a single entry to the underlying system of record, maybe a brand new value or an update to an existing value

Parameters:
key - the key of the mapping being installed or updated
value - the actual value being updated
Throws:
java.lang.Exception - if the write operation failed
See Also:
Cache.put(Object, Object)

writeAll

void writeAll(java.lang.Iterable<? extends java.util.Map.Entry<? extends K,? extends V>> entries)
              throws BulkCacheWritingException,
                     java.lang.Exception
Writes multiple entries to the underlying system of record. These can either be new entries or updates to existing ones. It is legal for this method to result in "partial success" where some subset of the entries are written. In this case a BulkCacheWritingException must be thrown (see below)

Parameters:
entries - the key to value mappings
Throws:
BulkCacheWritingException - This writer must throw this exception to indicate partial success. The exception declares which keys were actually written (if any)
java.lang.Exception - a generic failure. All entries will be considered not written in this case
See Also:
Cache.putAll(java.util.Map)

delete

void delete(K key)
            throws java.lang.Exception
Deletes a single entry from the underlying system of record.

Parameters:
key - the key to delete
Throws:
java.lang.Exception - if the write operation failed
See Also:
Cache.remove(Object)

deleteAll

void deleteAll(java.lang.Iterable<? extends K> keys)
               throws BulkCacheWritingException,
                      java.lang.Exception
Deletes a set of entry from the underlying system of record. It is legal for this method to result in "partial success" where some subset of the keys are deleted. In this case a BulkCacheWritingException must be thrown (see below)

Parameters:
keys - the keys to delete
Throws:
BulkCacheWritingException - This writer must throw this exception to indicate partial success. The exception declares which keys were actually deleted (if any)
java.lang.Exception - a generic failure. All entries will be considered not deleted in this case
See Also:
Cache.removeAll(java.util.Set)