Interface CacheLoaderWriter<K,V>
- Type Parameters:
K- the key type processed by this loader-writerV- the value type processed by this loader-writer
Cache in sync with another system.
Instances of this class should 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.
A similar thing will happen for the bulk version of the loading and writing methods and create the bulk version of the related exceptions.
-
Method Summary
Modifier and TypeMethodDescriptionvoidDeletes a single mapping.default voidDeletes multiple mappings.Loads a single value.Loads multiple values.voidWrites a single mapping.default voidWrites multiple mappings.
-
Method Details
-
load
Loads a single value.When used with a cache any exception thrown by this method will be thrown back to the user as a
CacheLoadingException.- Parameters:
key- the key for which to load the value- Returns:
- the loaded value
- Throws:
Exception- if the value cannot be loaded
-
loadAll
Loads multiple values.The returned
Mapshould containnullvalues for the keys that could not be found.When used with a cache the mappings that will be installed are the keys as found in
keysmapped to the results ofloadAllResult.get(key). Any other mappings will be ignored.By using a
BulkCacheLoadingExceptionimplementors can report partial success. Any other exceptions will be thrown back to theCacheuser through aBulkCacheLoadingExceptionindicating a complete failure.- Parameters:
keys- the keys to load //Which null or not present?- Returns:
- the
Mapof values for each key passed in, where no mapping means no value to map. - Throws:
BulkCacheLoadingException- in case of partial successException- in case no values could be loaded
-
write
Writes a single mapping.The write may represent a brand new value or an update to an existing value.
When used with a
Cacheany exception thrown by this method will be thrown back to the user through aCacheWritingException.- Parameters:
key- the key to writevalue- the value to write- Throws:
Exception- if the write operation failed
-
writeAll
default void writeAll(Iterable<? extends Map.Entry<? extends K, ? extends V>> entries) throws BulkCacheWritingException, ExceptionWrites multiple mappings.The writes may represent a mix of brand new values and updates to existing values.
By using a
BulkCacheWritingExceptionimplementors can report partial success. Any other exception will be thrown back to theCacheuser through aBulkCacheWritingExceptionindicating a complete failure.- Parameters:
entries- the mappings to write- Throws:
BulkCacheWritingException- in case of partial successException- in case no values could be written
-
delete
Deletes a single mapping.- Parameters:
key- the key to delete- Throws:
Exception- if the write operation failed
-
deleteAll
Deletes multiple mappings.By using a
BulkCacheWritingExceptionimplementors can report partial success. Any other exception will be thrown back to theCacheuser through aBulkCacheWritingExceptionindicating all deletes failed.- Parameters:
keys- the keys to delete- Throws:
BulkCacheWritingException- in case of partial successException- in case no values can be loaded
-