Interface CacheLoaderWriter<K,​V>

  • Type Parameters:
    K - the key type processed by this loader-writer
    V - the value type processed by this loader-writer

    public interface CacheLoaderWriter<K,​V>
    A CacheLoaderWriter is used to keep a 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.

    See Also:
    CacheLoadingException, CacheWritingException, BulkCacheLoadingException, BulkCacheWritingException
    • Method Detail

      • load

        V load​(K key)
        throws Exception
        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

        default Map<K,​V> loadAll​(Iterable<? extends K> keys)
                                throws BulkCacheLoadingException,
                                       Exception
        Loads multiple values.

        The returned Map should contain null values 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 keys mapped to the results of loadAllResult.get(key). Any other mappings will be ignored.

        By using a BulkCacheLoadingException implementors can report partial success. Any other exceptions will be thrown back to the Cache user through a BulkCacheLoadingException indicating a complete failure.

        Parameters:
        keys - the keys to load //Which null or not present?
        Returns:
        the Map of values for each key passed in, where no mapping means no value to map.
        Throws:
        BulkCacheLoadingException - in case of partial success
        Exception - in case no values could be loaded
      • write

        void write​(K key,
                   V value)
            throws Exception
        Writes a single mapping.

        The write may represent a brand new value or an update to an existing value.

        When used with a Cache any exception thrown by this method will be thrown back to the user through a CacheWritingException.

        Parameters:
        key - the key to write
        value - the value to write
        Throws:
        Exception - if the write operation failed
      • delete

        void delete​(K key)
             throws Exception
        Deletes a single mapping.
        Parameters:
        key - the key to delete
        Throws:
        Exception - if the write operation failed