Interface CacheWriter<K,V>
-
- Type Parameters:
K- the most general type of keys this writer can write; for exampleObjectif any key is acceptableV- the most general type of values this write can write; for exampleObjectif any value is acceptable
- All Known Implementing Classes:
DisabledWriter
@ThreadSafe public interface CacheWriter<K,V>Communicates the write or deletion of a value, based on a key, to an external resource. A writer is notified by the cache each time an entry is explicitly created or modified, or removed for anyreason. The writer is not notified when an entry is loaded or computed.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description voiddelete(K key, V value, RemovalCause cause)Deletes the value corresponding to thekeyfrom the external resource.static <K,V>
CacheWriter<K,V>disabledWriter()Returns a writer that does nothing.voidwrite(K key, V value)Writes the value corresponding to thekeyto the external resource.
-
-
-
Method Detail
-
write
void write(@Nonnull K key, @Nonnull V value)Writes the value corresponding to thekeyto the external resource. The cache will communicate a write when an entry in the cache is inserted or updated explicitly. The implicit creation of an entry due to being loaded when absent is not communicated.- Parameters:
key- the non-null key whose value should be writtenvalue- the value associated withkeythat should be written- Throws:
java.lang.RuntimeException- or Error, in which case the mapping is unchanged
-
delete
void delete(@Nonnull K key, @Nullable V value, @Nonnull RemovalCause cause)Deletes the value corresponding to thekeyfrom the external resource. The cache will communicate a delete when the entry is explicitly removed or evicted.- Parameters:
key- the non-null key whose value was removedvalue- the value associated withkey, ornullif collectedcause- the reason for which the entry was removed- Throws:
java.lang.RuntimeException- or Error, in which case the mapping is unchanged
-
disabledWriter
@Nonnull static <K,V> CacheWriter<K,V> disabledWriter()
Returns a writer that does nothing.- Type Parameters:
K- the type of keysV- the type of values- Returns:
- a writer that performs no operations
-
-